/USER\-[0-9]+\-[A-Z]{1}/
USER-345-A
USER-72-F
USER-1-R
USER-9-M
var arr = new Array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','X','Y','Z');
function getRandomFloat(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
document.write("USER-" + getRandomFloat(1, 999) + "-" + arr[Math.round(Math.random()*33)]);
$preg = '/USER\-[0-9]+\-[A-Z]{1}/';
$result = \str_replace(['\\', '/'], '', $preg);
\preg_match_all('/\[([\w\d-]+)\][{]*([\+\*\d,]+)[}]*/', $preg, $match);
$maxCount = 10;
if (!empty($match[0])) {
foreach ($match[1] as $key => $part) {
$part = \explode('-', $part);
$range = \range($part[0], $part[1]);
$countData = $match[2][$key];
if ($countData == '+') {
$count = \mt_rand(1, $maxCount);
} elseif ($countData == '*') {
$count = \mt_rand(0, $maxCount);
} else {
$countData = \explode(',', $countData);
if (isset($countData[1])) {
$count = \mt_rand($countData[0], $countData[1]);
} else {
$count = $countData[0];
}
}
$n = 0;
$generated = '';
$rangeTotal = \sizeof($range);
for ($n; $n < $count; ++$n) {
$randKey = \mt_rand (0, $rangeTotal - 1);
$generated .= $range[$randKey];
}
$replace = $match[0][$key];
$result = \str_replace($replace, $generated, $result);
}
}
echo $result;