They are called quantifiers.
* 0 or more from the previous expression
+ 1 or more from the previous expression
By default, the quantifier is greedy, which means that it matches the maximum possible number of characters.
? after the quantifier changes its behavior to make this quantifier “jagged”, means that it will match as little as possible.
Greedy / jagged example
For example, in the string "abab"
a.*b will match "abab" (preg_match_all will return one match, "abab")
while a.*?b will only match the start "ab" (preg_match_all will return two matches, "ab")
You can test your regular expressions online, for example. on regexr, see the greedy example here
stema Dec 20 '11 at 12:18 2011-12-20 12:18
source share