tags:

views:

38

answers:

1

Hello,

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?

+2  A: 

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.

Adam Bellaire
Where did that $ come from????? Thank you, Adam. I can't believe I made such a stupid mistake. That $ was sitting there and I simply didn't notice it!
Ree
You're welcome! Would it be fair to say then that you **accept my answer** as the solution to your question? *HINT HINT*
Adam Bellaire