in reply to Re^2: /g option not making s// find all matches (updated)
in thread /g option not making s// find all matches
... 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: <%-{-{-{-<
|
---|