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

In reply to Re: Regular Expn Problem by Roy Johnson
in thread Regular Expn Problem by venkatr_n

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.