in reply to Re^6: /g option not making s// find all matches (updated)
in thread /g option not making s// find all matches

What if you need the unmodified behavior?

But what unmodified behavior would you need that you would not be able to access in a fairly clear and simple manner? E.g., if you're using /s and you want the "match anything except a newline" behavior, does not  [^\n] best express this? (One of the driving motivations of TheDamian's regex PBPs is clarity of expression.)

Conversely, in the absence of /s, how would you best express "match anything at all, including a newline" (the most common use-case, IMO)? Something like  [\s\S] would do the trick, but is that anyone's idea of clarity? (And don't get me started on (?s:.) ...)

... with /x ... you can always just escape any literal space characters your regex needs. But ... all those escapes clutter the code ...

I must admit that the need for special handling of spaces can be annoying. But even this can advance clarity: [ ] (I would not use \) matches a blank space exactly; [ \t] matches a blank space or a tab exactly; \s matches any whitespace exactly; etc... (You may object that \s is too general, but there've been several occasions on which I've been saved from a 3 AM phone call by having used \s rather than a more specific [ ] — or even \) And \Q...\E can help out, too.

Anyway, TheDamian explains it all more completely and clearly than I can, so maybe pursue that avenue.


Give a man a fish:  <%-{-{-{-<

Replies are listed 'Best First'.
Re^8: /g option not making s// find all matches (updated)
by raygun (Scribe) on Jun 01, 2018 at 03:25 UTC
    if you're using /s and you want the "match anything except a newline" behavior, does not [^\n] best express this?
    In the context of /s, sure. But again, there is a larger context: someone else reading the regex will wonder at the incongruity of using /s at all in conjunction with a bunch of [^\n]s, when omitting the /s would simplify the whole thing (and also make the regex syntax match that used by most other regex engines, a consideration — albeit minor — when aiming for clarity).
    One of the driving motivations of TheDamian's regex PBPs is clarity of expression.
    A goal we can all agree with! Now, enter devils and details.
    Anyway, TheDamian explains it all more completely and clearly than I can, so maybe pursue that avenue.
    Point taken. I'm sure my perl experience is a tiny fraction of either yours or his.