I was browsing old php sources and I found a pattern I don\'t understand (probably a copy/past from the internet some times ago ...).
Here is a simple exemple using
+
is a greedy operator; consuming as much as possible. Therefore, .+
will match as much as it can and still allow the remainder of the regular expression to match. Once you specify the question mark +?
, you're telling the regex engine (don't be greedy.. as soon as you find a double quote "
... stop, you're done.)
The ?
makes the match non-greedy, meaning that the expression .+?
will match as few characters as possible to make the regex match, rather than matching as any as possible, which is the default behaviour.