in reply to zero-width assertions in perl regular expression

perlre can:

\Z Match only at end of string, or before newline at the end
\z Match only at end of string

Update Consider:

my $str = "The quick abc"; for my $regex ('\babc\z', '\babc\Z') { print "Matched with newline using $regex\n" if "$str\n" =~ $regex; print "Matched without newline using $regex\n" if $str =~ $regex; }

Prints:

Matched without newline using \babc\z Matched with newline using \babc\Z Matched without newline using \babc\Z

True laziness is hard work

Replies are listed 'Best First'.
Re^2: zero-width assertions in perl regular expression
by leslie (Pilgrim) on Feb 28, 2009 at 10:47 UTC

    Thanks for your replay.
    Its clarifies me.