in reply to Strange regex to test for newlines: /.*\z/
perl -le '$_ = "foo\n";print "string with trailing newline" if !/.*\z/ + and /.*\z/s' string with trailing newline perl -le '$_ = "foo\nbar";print "string with trailing newline" if !/.* +\z/ and /.*\z/s'
Otherwise the matching stops at the newline, but that isn't the end of the string. It is a single line if you match the end with '$', but after the \n, you are on the next line, and the end of the string happens to be there. How can I put it? It seems logical to me, but I've got to struggle yet with wording.. I'll update this post until I've got it, sorry for that.
update - seems like Ojosh!ro found the right words. Ojosh!ro++, thanks :-)
--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^2: Strange regex to test for newlines: /.*\z/
by moritz (Cardinal) on May 21, 2007 at 13:56 UTC | |
by shmem (Chancellor) on May 21, 2007 at 14:26 UTC | |
by moritz (Cardinal) on May 21, 2007 at 15:10 UTC | |
by shmem (Chancellor) on May 21, 2007 at 15:47 UTC | |
by demerphq (Chancellor) on May 21, 2007 at 23:42 UTC | |
| |
by tinita (Parson) on May 21, 2007 at 14:53 UTC | |
by shmem (Chancellor) on May 21, 2007 at 15:44 UTC | |
by betterworld (Curate) on May 22, 2007 at 00:46 UTC |