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

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

by xicheng (Sexton)
on May 21, 2007 at 16:57 UTC ( #616602=note: print w/ replies, xml ) Need Help??

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

hmm, Just notice that, thanks..

I think, .* and .{0,} at the beginning of a regex pattern shold have been treated as optional, so that /.*A/ and /.{0,}A/ should be the same as /A/ which means .* and .{0,} are completely unnecessary in the above patterns..

But \z looks behave very differently to .* and .{0,} as you mentioned.

This looks like a Perl-related problem, PHP(use a similar regex engine) does it pretty well:

php -r ' $str = "foo\n"; if (preg_match("/.*\z/", $str)) { print "match\n"; } ' match
Probably it's a bug, and I am waiting for someone to make it clear. :-)


Comment on Re^4: Strange regex to test for newlines: /.*\z/
Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (11)
As of 2015-11-25 16:31 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (683 votes), past polls