I agree with what you say regarding the flexibility of the (?i) construct over the global m{...}i one but I think I would take issue with your second paragraph.

... the unvarying use of the /xms regex modifier 'tail' (if that's the proper term) is to give the ^ $ . regex operators unvarying behaviors ...

While they are very rarely used that way, m, s and even x are no more invariant than i and can be sprinkled throughout your regular expression. To give a nonsense example:

knoppix@Microknoppix:~$ perl -E ' > $_ = qq{aabb\nwxy935TXB\n123}; > say $1 if m{(?x) ( a [^a] (?s) .* 9 (?-s) .* ) };' abb wxy935TXB knoppix@Microknoppix:~$
I'm also under the impression that (?i) need not be confined solely to the scope of capturing and non-capturing groups but can also be used as a "switch" to change the matching behaviour from the point at which it appears onwards or in its own "modifier" group ((?i:pattern)) for want of a better word. The following patterns are examples of how I understand the modifiers can be used:

m{(?i)Whole pattern case-insensitive} m(Case-Sensitive(?i)case-insensitive(?-i)Case-Sensitive Again} m{Case-Sensitive((?i)except in this capture)Case-Sensitive Again} m{Case-Sensitive(?i:but not here)Case-Sensitive Again} m{all case-insensitive(?-i:Except Here) and insensitive again}i m{(?x) Use white-space\sfor readability(?-x)but literal spaces now};

PBP is a fascinating book with very well argued recommendations that make you wonder whether you are doing things the right way. I believe that there are two equally valid reactions to each recommendation in the book: follow the recommendation if, after consideration, it seems better than what you were doing before; alternatively, if you can come up with equally cogent arguments for continuing the way you were, then do that. The main thing is that the book has made you think.

Cheers,

JohnGG


In reply to Re^4: Capturing string matched by regex by johngg
in thread Capturing string matched by regex by tunafish

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.