Using the string ABC123 as my subject, matching [A-Z]* does match "ABC" as intended, but trying to match [0-9]* returns an empty string. I'm under the assumption that preg_match is greedy by default, and those two very similar regular expressions behave really differently
Asked
Active
Viewed 63 times
0
-
1Use `[0-9]+`, else `[0-9]*` matches an empty string before the first char that is not a digit. – Wiktor Stribiżew Dec 25 '17 at 22:10
-
it prefers to match 0 digits earlier in the string to 3 digits later in the string. – ysth Dec 25 '17 at 22:44