in reply to Re: Do nothing? or Do something important in a very obscure way?
in thread Do nothing? or Do something important in a very obscure way?

I'm genuinely not sure if you answered my dilemma or not:)

Does "it tries to match x zero times" mean, it just moves on to the next part of the regex and doesn't bother looking at the string under inspection, effectively completely ignoring the presence of 'x??' or 'x*?'? Or does it look to make sure that there isn't an 'x' in the string between the current point and the next significant point?


What's this about a "crooked mitre"? I'm good at woodwork!
  • Comment on Re: Re: Do nothing? or Do something important in a very obscure way?

Replies are listed 'Best First'.
Re: Re: Re: Do nothing? or Do something important in a very obscure way?
by Anonymous Monk on Aug 23, 2002 at 10:58 UTC
    The RE engine is a recursive search for ways to try to match the pattern to the string.

    'x??' means that it notes that it has a decision, and first tries to match no x's. If it fails then it will backtrack, reconsider that decision, and try to match one x then go forward. If that fails, then you fail.

    'x*?' is similar. It notes that it has a decision, and first tries to match no x's. If it fails then it will backtrack, try to match one x, and then try to make the same decision over again. (That is the difference between the * and the ?. The ? will try to match at most once then proceed. The * returns to trying to match the preceeding group, and therefore can match there an unlimited number of times.)

    If that didn't make sense then pick up Mastering Regular Expressions by Friedl. He explains it better.

      Please see my update to the post regarding context!


      What's this about a "crooked mitre"? I'm good at woodwork!
Re: Re: Re: Do nothing? or Do something important in a very obscure way?
by theorbtwo (Prior) on Aug 23, 2002 at 09:00 UTC

    Yes. <g>

    By "it tries to match x zero times", I meant "it ignores the atom". I should point out that I'm hardly an expert.


    Confession: It does an Immortal Body good.