[php]$input = “13:”;
$regexp = “/([2-9][:])|([0][2-9][:])|([1][0-2][:])|([1][:])/”;
if (preg_match ($regexp, $input) === 1) {
echo “Match!”;
}
else {
echo “NO match.”;
}[/php]
Why is this a match? I don’t understand.
[php]$input = “13:”;
$regexp = “/([2-9][:])|([0][2-9][:])|([1][0-2][:])|([1][:])/”;
if (preg_match ($regexp, $input) === 1) {
echo “Match!”;
}
else {
echo “NO match.”;
}[/php]
Why is this a match? I don’t understand.
Because you aren’t forcing the match on the whole string, it will look for any of those groups in the specified string, in this case it will match “3:” based on the first group. If you want to make sure it’s matching the whole thing your regex needs to follow this syntax:
/^ABCDE...XYZ$/
^ = Start
$ = End