in reply to Re(3): Possessive Quantifiers
in thread Possessive Quantifiers

I'm guessing that (?>a*b*) is equivalent to Java's a*+b*+.

The equivalent to Java's a*+b*+ would be (?>a*)(?>b*). In this case that wouldn't make a difference of course, but it would in situations like this one:

$_ = "aaab"; print "/(?>[ab]+)(?>b+)/ matches $_\n" if /(?>[ab]+)(?>b+)/; print "/(?>[ab]+b+)/ matches $_\n" if /(?>[ab]+b+)/;
What about (?>a*(b|c)d*)? Can that be expressed in Java at all?

How about (a*(b|c)d*){1}+? (Yeah, it's ugly...)

— Arien

Replies are listed 'Best First'.
Re: Re(4): Possessive Quantifiers
by Ferret (Scribe) on Aug 18, 2002 at 17:36 UTC

    > How about (a*(b|c)d*){1}+? (Yeah, it's ugly...)

    Yup, it is. But that's why we keep the uglier but more appropriate (?>) around in Perl. Occasionally, it's the right/only operator for the job.

    As best as I can figure, java thinks it's being clever by using the possessive instead of (?>), which is dumb, since it doesn't cover the simple case of exactly one match. We can do better than that :-)