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

Re: Regex bug in 5.10 (was: Using Look-ahead and Look-behind)

by jds17 (Pilgrim)
on May 08, 2009 at 19:47 UTC ( [id://762920]=note: print w/replies, xml ) Need Help??


in reply to Regex bug in 5.10 (was: Using Look-ahead and Look-behind)
in thread Using Look-ahead and Look-behind

You are right, my change did not affect greediness. The bad thing is: now I don't understand why my proposed solution worked at all. Maybe someone can explain? I don't think the question is too important, but I like to use regular expressions and it bugs me a little if I cannot understand one (especially such a tiny one).

I have read the documentation you have cited and it helped, so I played around some more and tried out the following, which only exchanges "+" for "*" in your original expression, really works as one would think and therefore would be my preferred solution, at least for Perl 5.10:

$_ = "Hello"; print "$1\n" while /(?=(.+))/g;
Output:
Hello ello llo lo o

Replies are listed 'Best First'.
Re^2: Regex bug in 5.10 (was: Using Look-ahead and Look-behind)
by ikegami (Patriarch) on Nov 28, 2024 at 17:00 UTC

    Note that using + instead * is not equivalent.

    $ perl -e'$_ = "Hello"; print "<$1>\n" while /(?=(.*))/g;' <Hello> <ello> <llo> <lo> <o> <> $ perl -e'$_ = "Hello"; print "<$1>\n" while /(?=(.+))/g;' <Hello> <ello> <llo> <lo> <o>

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://762920]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2026-02-11 01:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.