Come for the quick hacks, stay for the epiphanies. | |
PerlMonks |
Re^5: Capturing string matched by regexby AnomalousMonk (Archbishop) |
on Feb 18, 2012 at 02:41 UTC ( [id://954680]=note: print w/replies, xml ) | Need Help?? |
... I think I would take issue with your second paragraph.... the unvarying use of the /xms regex modifier 'tail' ...While they are very rarely used that way, m, s and even x are no more invariant than i ... What I meant to convey by my reference to "/xms-tail invariance" was that this is the PBP recommendation (original post amended) and that the reason for this is to nail down the behavior of the ^ $ . critters. For this reason, I regard with horror the idea of sprinkling (?-x) (?m) (?-s) et al through the regex due to the extreme danger of brain meltdown and subsequent containment breach. For those cases in which one might be tempted to the Dark Side, e.g., the use of (?-s:.) in case an "anything-but-a-newline" match is needed (always assuming an /xms tail), PBP discusses alternatives; in the foregoing example, [^\n] (or in 5.12+, the "experimental" \N sequence). I'm also under the impression that (?i) need not be confined solely to the scope of capturing and non-capturing groups ... My discussion of the behavior of (?pimsx-imsx) patterns was brief, vague and lacking. I've tried to remedy this with a link to the docs. The following patterns are examples of how I understand the modifiers can be used ... I haven't tested these, but they look syntactically correct. However, I would quibble with most, especially the latter ones, on stylistic grounds. I haven't time now, but may return to this point with a detailed discussion of my own preferences. PBP is a fascinating book with very well argued recommendations ... I agree with every statement in this paragraph.
In Section
Seekers of Perl Wisdom
|
|