Regex will be difficult for this one, and that regex may look hideous as well.
Instead of the regex, you can split the String into two parts, first one will have only AB
and the second one will have only the number. Then check the number whether its inside the range or not.
$string = "AB200000";
$splits = preg_split("/(?<=^AB)(?=\d{6}$)/", $string);
if($splits[1] >= 1 && $splits[1] <= 200000){
print "bingo!\n";
}
You can use substr()
instead of preg_split()
.