although the \G in your version isn't doing anything in this case. I believe (but am open to correction) that \G doesn't have any effect unless you also use the /c modifier and even then, it only has an effect once a failure has occurred in which case, a subsequent match on the same target string will start from the point of the previous failure.

then let me correct ;-)

The '\G' forces the next match to start where the last ended. When the regex is executed the first time, '\G' is thus equivalent to '\A' (beginning of string). The next matches (due to the /g modifier) have to start where the previous one ended, so no part of the string can be skipped. This sure makes a difference, see the examples below.

sub test_regex { local $_ = shift; local $\ = "\n"; print 'string: ', $_, ; print 'with \G: ', join(':', m/\G ( [0-9A-Z]{1,2} ) (?: :|$ ) / +igx); print 'without \G: ', join(':', m/ ( [0-9A-Z]{1,2} ) (?: :|$ ) / +igx), "\n"; } test_regex('0:0A:0C:B:B8:F'); test_regex('#0:0A:0C:B:B8:F'); test_regex('0: 0A:0C:B:B8:F'); test_regex('0:0Aa:0C:B:B8:F');

-- Hofmator


In reply to Re3: Capturing brackets within a repeat group by Hofmator
in thread Capturing brackets within a repeat group by BrowserUk

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.