Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: Quirky regex bug

by Corion (Pope)
on Jan 07, 2002 at 02:35 UTC ( #136721=note: print w/replies, xml ) Need Help??

in reply to Quirky regex bug

Just to add a small diagnosis from symptoms without looking at the source code, the problem seems to be * specific, as fixed-width REs work (at least with 5.6.1), like :

print $1 if 'abcfoobc' =~ /(.*)foo\1/; # works print $1 if 'abcfoobc' =~ /(.*).{3}\1/; # does work, $1 empty print $1 if 'abcfoobc' =~ /(.+)foo\1/; # works as well

Update: Thanks to chipmunk, I figured out that I was dumb. The following RE also matches :

print $1 if 'abcfoobc' =~ /(.*)\w*\1/; # does work

perl -MHTTP::Daemon -MHTTP::Response -MLWP::Simple -e ' ; # The $d = new HTTP::Daemon and fork and getprint $d->url and exit;#spider ($c = $d->accept())->get_request(); $c->send_response( new #in the HTTP::Response(200,$_,$_,qq(Just another Perl hacker\n))); ' # web

Replies are listed 'Best First'.
Re: Re: Quirky regex bug
by japhy (Canon) on Jan 07, 2002 at 02:41 UTC
    Yes. From the source (regcomp.c:1851):
    else if (!sawopen && (OP(first) == STAR && PL_regkind[(U8)OP(NEXTOPER(first))] == REG_ANY) && !(r->reganch & ROPT_ANCH) ) { /* turn .* into ^.* with an implied $*=1 */ /* ... */ }
    So you can see it is only for regexes starting with .* -- if you look a few lines up, you see:
    /* Skip introductions and multiplicators >= 1. */ while ((OP(first) == OPEN && (sawopen = 1)) || /* ... */ ) { /* ... */ }
    So it's ignoring the fact that the .* might actually be inside parens.

    My patch consisted of the text "!sawparen &&" in the code block up top. Big patch, I know.

    Jeff[japhy]Pinyan: Perl, regex, and perl hacker.
    s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://136721]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2017-11-23 04:29 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (328 votes). Check out past polls.