Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

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

by shmem (Chancellor)
on May 21, 2007 at 15:44 UTC ( [id://616592]=note: print w/replies, xml ) Need Help??


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

"\n" =~ /\n.*\z/; # matches

Obvious, I think. You match a "\n", then EOS (end of string).

"\n" =~ /.*\z/; # doesn't match. i would expect it to match

perl -D512 tells anchored(MBOL) (i.e. multiline beginning of line, see perldebguts) with that one, which anchoring doesn't happen with

"\n" =~ /[^\n]*\z/; # matches. like expected. but [\n]* is like .*

but why?

"\n" =~ /.?\z/;

matches, as does

"\n" =~ /.{0,}\z/;

I can't get a mental model of why the previous one should, but the next one should not match:

"f\n" =~ /.?f\z/;

Weird. Rather inconsistent, if not buggy.

--shmem

_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

Replies are listed 'Best First'.
Re^6: Strange regex to test for newlines: /.*\z/
by betterworld (Curate) on May 22, 2007 at 00:46 UTC
    "\n" =~ /\n.*\z/; # matches
    Obvious, I think.

    If this one is obvious, then the original one should be obvious too. Compare:

    "\n" =~ /\n.*\z/; # matches "\n" =~ /.*\z/; # should match but doesn't

    The pattern gets shorter, but doesn't match any more...

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-19 13:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found