Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^5: \s does not match end-of-line

by AnomalousMonk (Archbishop)
on Feb 06, 2018 at 06:08 UTC ( [id://1208539]=note: print w/replies, xml ) Need Help??


in reply to Re^4: \s does not match end-of-line
in thread /s does not match end-of-line

My personal regex best practices (solidly in line with TheDamian's as given in his PBP book) include reserving  ^ $ for matching around embedded newlines (which means that the  /m regex modifier is always asserted) and using  \A \z \Z as "absolute" string start/end anchors. To the best of my recollection,  \A \z \Z were introduced with Perl 5, sometime prior to 1996 (update: but see hippo's correction).

... is there something which "\Z" can do which "$" does not??

It's the other way around:  ^ $ match also around embedded newlines (with the ever-present  /m modifier), while  \A \z \Z match only at string start/end; hence, in a sense, they do less. The advantage of this practice is that you never have to think about what  ^ $ do; also,  \A \z \Z cannot be modified.


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

Replies are listed 'Best First'.
Re^6: \s does not match end-of-line
by hippo (Bishop) on Feb 06, 2018 at 10:28 UTC
    To the best of my recollection, \A \z \Z were introduced with Perl 5, sometime prior to 1996.

    Not quite. \z at least was introduced with perl 5.005 in 1998. I believe that the others do predate this, however.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-04-23 07:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found