Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: regular expression and grep function questions

by kcott (Abbot)
on Mar 02, 2013 at 00:49 UTC ( #1021369=note: print w/ replies, xml ) Need Help??


in reply to regular expression and grep function questions

G'day dicty,

\z is used in regular expressions as an anchor to match the end of a string (which could be multi-line). It differs from $ which matches the end of a line; and, it is subtly different from \Z (uppercase Z) which matches the end of the string but optionally before a newline if one exists.

The following code demonstrates each of these differences:

$ perl -Mstrict -Mwarnings -E ' my $string = "abc\ndef\n"; $string =~ /(.*?)$/ms; say q{[$]}, $1, q{[$]}; $string =~ /(.*?)\z/ms; say q{[z]}, $1, q{[z]}; $string =~ /(.*?)\Z/ms; say q{[Z]}, $1, q{[Z]}; ' [$]abc[$] [z]abc def [z] [Z]abc def[Z]

Under perlre - Regular Expressions, $ is described in the Metacharacters section and \z and \Z are described in the Assertions section.

I see hippo has answered your second question.

-- Ken


Comment on Re: regular expression and grep function questions
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (3)
As of 2015-07-04 17:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (60 votes), past polls