Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^5: Capturing string matched by regex

by AnomalousMonk (Archbishop)
on Feb 18, 2012 at 02:41 UTC ( [id://954680]=note: print w/replies, xml ) Need Help??


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

... 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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://954680]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2024-04-26 06:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found