I have a regex in PHP to match some text like this:
24th Meeting – The quick brown fox [10 January 2012 to 26 September
2012]
The pattern I’ve come up with looks like this:
$pattern = "/(([0-9]{1,2})(st|nd|rd|th)\sMeeting\s-\s)?(.*)(\[([0-9]{1,2}\s(January|February|March|April|May|June|July|August|September|November|December)\s[0-9]{4})\sto\s([0-9]{1,2}\s(January|February|March|April|May|June|July|August|September|November|December)\s[0-9]{4})\])$/"
This seems to work fine.
However, I would like the date portion at the end to be optional. BUT, when I add a ? after the dates grouping, preg_match no longer pulls out the dates if they are in the string. I suspect that the .* is taking over, but I can’t seem to get it
Read more about lazy quantifiers here:
http://www.regular-expressions.info/repeat.html