develooper Front page | perl.perl5.porters | Postings from June 2021

Re: qr'$foo' and unescaped $ signs

Thread Previous | Thread Next
From:
Eirik Berg Hanssen
Date:
June 30, 2021 13:05
Subject:
Re: qr'$foo' and unescaped $ signs
Message ID:
CAHAeAG7mwTZ5_z-pHpgn-fAhVvLjvFrXM-9s3_mdRXJCsHEPTA@mail.gmail.com
On Wed, Jun 30, 2021 at 12:42 PM Nicholas Clark <nick@ccl4.org> wrote:

> It seems that if $ is matched, it needs to be the (logical) end of the
> pattern, else the entire pattern matches. By "logical", I mean that other
> text follow in the regex, but it needs to be other alternations, or
> something
> else that doesn't contribute to matching. It can't be more characters, even
> if they are present on the next line.
>

  You can match more characters, but you need to consume the newline
first.  (The $ is a zero-width lookahead assertion – it does not consume
anything.)

eirik@rustybox[14:54:32]~$ perl
use 5.16.0;
for (qr'$\sbar'm, qr'$.*bar'ms) {
  say "foo\nbar" =~ $_ ? "Matched: $&" : "Nope"
}
__END__
Matched:
bar
Matched:
bar
eirik@rustybox[15:00:14]~$

basically, is there any string that qr'$foo'm will match?
>

  No, no more than there is a string that qr/(?=bar)foo/ will match.  Need
to consume that bar first.


Eirik

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About