in reply to Regular Expn Problem

You should include the last .+ in the grouping with Other:
... G\s+(\d+)(?:.+ Other\s(\d+))?/sx;
Update: This problem is a good illustration of the difference between lazy and greedy. Perl regexps are both, and you can't fix a problem with one by addressing the other.

Greediness is about gobbling up characters. Laziness is about backtracking. Perl will not backtrack unless it fails to match. So .+ is going to match clear to the end of the text (or line) unless there is something mandatory after it. .+? is going to match exactly one character unless there is something mandatory after it.

Perl will not backtrack outside of an optional subexpression to try to match it, so any backtracking you want it to do should be inside the optional subexpression.


The PerlMonk tr/// Advocate