develooper Front page | perl.perl5.porters | Postings from March 2013

Re: Is this a /^*/ bug?

Thread Previous | Thread Next
From:
Brad Gilbert
Date:
March 25, 2013 16:17
Subject:
Re: Is this a /^*/ bug?
Message ID:
CAD2L-T0BTW8wL9d5PD9vOPXQ87C_8fQ4PhboS73dXUMNcvq1TQ@mail.gmail.com
On Mon, Mar 25, 2013 at 10:55 AM, Tom Christiansen <tchrist@perl.com> wrote:
> I realize this is nonsense, but I wonder if it is not a bug.  Shouldn't the
> overall pattern still fail, not succeed?
>
>     % perl -WE 'say "foo.bar" =~ /^.*.bar$/ || "FAIL"'
>     1
>
>     % perl -WE 'say "foo.bar" =~ /^*.bar$/ || "FAIL"'
>     ^* matches null string many times in regex; marked by <-- HERE in m/^* <-- HERE .bar$/ at -e line 1.
>     1
>
>     % perl -WE 'say "foo.bar" =~ /(^*).bar$/ || "FAIL"'
>     ^* matches null string many times in regex; marked by <-- HERE in m/(^* <-- HERE ).bar$/ at -e line 1.
>     1
>
>     % perl -WE 'say "foo.bar" =~ /^.bar$/ || "FAIL"'
>     FAIL
>
> Tested with v5.8.8, v5.14.0, v5.16.0, and v5.17.0-352-g3630f57.
>
> --tom

    $ perl -WE'say "foo.bar" =~ /^+.bar/ || "FAIL"'
    ^+ matches null string many times in regex; marked by <-- HERE in
m/^+ <-- HERE .bar/ at -e line 1.
    FAIL

    $ perl -WE'say "foo.bar" =~ /^?.bar/ || "FAIL"'
    1

`"foo.bar" =~ /^*.bar/` doesn't  fail because it allows `^` to not
match anything
thus allowing it to start to match later in the string.

    $ perl -WE '"foo.bar" =~ /^*.bar$/; say $&'
    ^* matches null string many times in regex; marked by <-- HERE in
m/^* <-- HERE .bar$/ at -e line 1.
    .bar

Imagine if the `^` were replaced with `\b`, another zero width assertion

    $ perl -WE '"foo.bar" =~ /\b*.bar$/; say $&'
    \b* matches null string many times in regex; marked by <-- HERE in
m/\b* <-- HERE .bar$/ at -e line 1.
    .bar

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