Reputation: 6211
Here's a short regex example:
preg_match_all('~(\s+|/)(\d{2})?\s*–\s*(\d{2})?$~u', 'i love regex 00– / 03–08', $matches);
print_r($matches);
The regex only matches '03–08', but my intention was matching '00–' as well. What is the problem? Anyone could explain?
Upvotes: 0
Views: 81
Reputation: 110429
The portion at the end:
-\s*(\d{2})?$~u
Means that you can only have spaces and/or optionally two digits between your match and the end of the string. This means 00-
can't match since there's other stuff between it and the end of the string.
If you remove the $
, it should work as you intend.
Upvotes: 2