in reply to Re^3: /g option not making s// find all matches (updated)
in thread /g option not making s// find all matches
The following all work identically:That's brilliant and kind of hurts my brain... :-)\G (?! \A) \G (?<! \A) (?! \A) \G (?<! \A) \G
In line with TheDamian's regex Perl Best Practices, I always use an /xms tail on every qr// m// s/// expression I write.Thanks for the pointer to that. I'll look more into it. In general, I like to use default behaviors unless I need to do something that the default can't accomplish. Then the mechanism to override the default (appending /xms in this case) becomes part of the code's self-documentation, alerting the reader that something outside the norm is happening. (That philosophy fails if some program or interface's defaults are insane, but in my experience, perl's are pretty solid.)
Also, from a readability standpoint, if you have ten regexes, nine of which end in / and the tenth ending in /m, it's easy to see at a glance that the tenth is doing something outside the default. But if you define your default to be /xms, in code with nine regexes ending in /xms and a tenth ending in /xs, the reader is much more likely to overlook the fact that the tenth instance is overriding the local default.
But, again, I say all this without having digested the rationale for TheDamian's recommendations, so it's all FWIW.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^5: /g option not making s// find all matches (updated)
by hippo (Archbishop) on May 31, 2018 at 08:55 UTC | |
Re^5: /g option not making s// find all matches (updated)
by AnomalousMonk (Archbishop) on May 31, 2018 at 14:10 UTC | |
by raygun (Scribe) on May 31, 2018 at 20:09 UTC | |
by AnomalousMonk (Archbishop) on May 31, 2018 at 21:21 UTC | |
by raygun (Scribe) on Jun 01, 2018 at 03:25 UTC | |
Re^5: /g option not making s// find all matches (updated)
by Your Mother (Archbishop) on May 31, 2018 at 09:06 UTC | |
Re^5: /g option not making s// find all matches (updated)
by AnomalousMonk (Archbishop) on Jun 01, 2018 at 17:31 UTC | |
Re^5: [DUP, Please REAP] /g option not making s// find all matches (updated)
by AnomalousMonk (Archbishop) on Jun 01, 2018 at 17:16 UTC |