in reply to Re: Regular Expn Problem
in thread Regular Expn Problem

I was under the impression that the ? at the end of .+? makes it be "not greedy" and allows the conditional at the end to be matched, but now I'm confused. I can use the exact expression without the conditional at the end, and with .+ instead of .+? and the regexp works correctly. So what is the ? in .+? doing?

Replies are listed 'Best First'.
Re: Re: Re: Regular Expn Problem
by BrowserUk (Patriarch) on May 10, 2004 at 06:49 UTC

    Your right, the ? does make .+? non-greedy, but the (?:...)? say that you don't mind if the contained expression is missing, so as the .+? can match to the end (of any string), then no attempt is made to match the optional expression that follows it.

    Hmm. Maybe this makes more sense? The earlier expression does match to the end of string, and the later (rightmost) expression is optional, so no attempt is made to match the latter.


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail