Cases where possessive and greedy quantifiers of `*+` and `*` give different results?

Viewed 132

I was looking at this question Greedy vs. Reluctant vs. Possessive Quantifiers

I can see how *+ and * both match zero or more times, but the possessive quantifier *+ will match forwards as much as possible.. And the * will do .* and backtrack. And I can accept that *+ would be more efficient when the .* string is long.

I'm interested in when they give different results though.

And I saw a comment

@moodboom, there are zero cases ever (mathematical fact) where possessive quantifiers will produce a match that will not be produced by simple greedy quantifiers. There are occasional cases where they will produce a no match when greedy quantifiers would produce a match. For ALL other cases (where greedy and possessive produce the same results), possessive quantifiers give a performance gain. – Wildcard May 5 at 23:00

I'd be very interested to see this expanded upon, specific cases where possessive and greedy quantifiers give a different result.

Contrasting *+ and *

I'd also be interested in the case of what different results are possible, contrasting ?+ vs ?

2 Answers
Related