In php, I have the following situation:
$Text = "eb 6; 1 cor 4";
$Regex1 = '((eb 6(; 1)?|1 cor 4)(; )?)+';
$Regex2 = '((eb 6|1 cor 4)(; )?)+';
$Match1 = preg_match("/$Regex1/", $Text, $ArrayMatches1);
$Match2 = preg_match("/$Regex2/", $Text, $ArrayMatches2);
$Regex2
matches the whole variable: eb 6; 1 cor 4
$Regex1
ends matching eb 6; 1
.
Now, PCRE's are supposed to be greedy; since $Regex2
is equivalent to $Regex1
with (; 1)
used 0 times, I'd expect $Regex1
to return the longest possible match, while it doesn't happen: it seems that the quantifiers are greedy, but the whole pcre isn't greedy.
Am I missing something or is this a php bug?