in reply to Re^2: Capturing string matched by regex
in thread Capturing string matched by regex
... more consistent ...
I haven't gone back to review in detail the rationale presented in Perl Best Practices (PBP), but off the top of my head...
Of course, the reason for Update: the PBP recommendation of the unvarying use of the /xms regex modifier 'tail' (if that's the proper term) is to give the ^ $ . regex operators unvarying behaviors, and the programmer a few fewer things to worry about; because they're always there, their proper place is in the tail.
One thing that cannot be made invariant from regex to regex is case insensitivity. Where, then, to put the /i modifier? If in the modifier tail, it's in danger of being 'lost', and moreover has global effect upon the regex. If in the body of the regex, it's in your face, and has the added advantage of being more flexible: the effects of the (?i) and (?-i) extended pattern modifiers are dependent upon the 'scoping' of the regex capturing and non-capturing groups in which they may appear (Update: see docs linked below for details).
I.e., the mixture of qr{pat}xms with qr{pat}xmsi (or m// or s///) regex definitions is actually less consistent! Moreover, the (?i) extended pattern allows one to precisely define and control the desired matching behavior.
Of course, the PBP recommendations are not without controversy. I will only repeat the words of a great Marxist philosopher (Groucho): "These are my principles. If you don't like them, I've got others."
See Extended Patterns in perlre for detailed info on the behavior of "(?pimsx-imsx)" and "(?imsx-imsx:pattern)" patterns, especially on the 'scope' of their effect.
Updates:
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Capturing string matched by regex
by johngg (Canon) on Feb 18, 2012 at 00:08 UTC | |
by AnomalousMonk (Archbishop) on Feb 18, 2012 at 02:41 UTC |