... the \G (?! \A) construct ... how it works ...

This simply asserts that \G (at previous match point or at absolute start of string if first match) is true, and that \A (at absolute start of string) is not true; i.e., that \G is not matching at the start of the string. This is a little confusing in that  (?! ...) is a negative look-ahead and you may wonder how one can look ahead to the absolute start of a string. However, \G and \A are both zero-width assertions, so it doesn't matter which way you look as long as you're negating. The following all work identically:
    \G (?! \A)    \G (?<! \A)    (?! \A) \G    (?<! \A) \G

The /ms options seem unnecessary here; did you include them just to make the solution as generic as possible?

In line with TheDamian's regex Perl Best Practices, I always use an  /xms tail on every  qr// m// s/// expression I write. Of course, /x allows whitespace and comments; can't be bad. In addition,  ^ $ . always behave in the same way and I don't have to think about it any more; regexes are complicated enough as it is. E.g., the behavior of  . (dot) is "by default, dot matches everything except a newline unless the /s modifier is asserted, in which case dot matches everything — now let's see whether or not there's a /s around anywhere". TheDamian recommends and I prefer to always use the /s modifier and just think about the behavior of dot as "dot matches all". Period. Similarly for the  ^ $ assertions and the /m modifier. (In general, I have quite a bit of respect for TheDamian's PBPs. I don't agree with them all, but I have embraced the regex PBPs completely and wholeheartedly.)

So in answer to your direct question, the universal  /xms tail is not used to make regexes generic so much as to make them less-thought-needed-ic.


Give a man a fish:  <%-{-{-{-<


In reply to Re^3: /g option not making s// find all matches (updated) by AnomalousMonk
in thread /g option not making s// find all matches by raygun

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.