Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^3: Strange regex to test for newlines: /.*\z/

by moritz (Cardinal)
on May 21, 2007 at 14:02 UTC ( #616563=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Strange regex to test for newlines: /.*\z/
in thread Strange regex to test for newlines: /.*\z/

.* will match anything but a newline, or the empty string.

So I'd expect "foo\n" =~ /.*\z/; to match, but capture the empty string in $&, not "foo\n".

Of course there are more elaborate ways to match for a newline character ;-)


Comment on Re^3: Strange regex to test for newlines: /.*\z/
Download Code
Re^4: Strange regex to test for newlines: /.*\z/
by mrpeabody (Friar) on May 22, 2007 at 20:37 UTC
    .* will match anything but a newline, or the empty string.

    It will match both of those, actually, as it should.

    506 $ perl -we'print "yes" if "" =~ /.*/' yes 507 $ perl -we'print "yes" if "\n" =~ /.*/' yes

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (10)
As of 2014-10-22 07:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (114 votes), past polls