Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to match string end for a multiline string?

0 views
Skip to first unread message

Peng Yu

unread,
Jun 22, 2008, 12:28:59 PM6/22/08
to
Hi,

$ matches line end. When a string has multiple lines, how to much the
last line end?

Thanks,
Peng

Damian Lukowski

unread,
Jun 22, 2008, 12:33:27 PM6/22/08
to
> The "\A" and "\Z" are just like "^" and "$",
> except that they won't match multiple times when the "/m" modifier is
> used, while "^" and "$" will match at every internal line boundary. To
> match the actual end of the string and not ignore an optional trailing
> newline, use "\z"

Tad J McClellan

unread,
Jun 23, 2008, 10:32:35 PM6/23/08
to
Peng Yu <Peng...@gmail.com> wrote:


> $ matches line end.


No, it matches end of string, not end of line.

If used with //m, _then_ it matches end of line.


> When a string has multiple lines, how to much the
> last line end?


/$/


See it for yourself:

-------------------------------
#!/usr/bin/perl
use warnings;
use strict;

$_ = '
foo
bar
baz
';

s/$/END-OF-STRING/;

print;
-------------------------------


--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"

0 new messages