in reply to Re^3: simple pattern match ?
in thread simple pattern match ?

So it does :)

So my logic above is flawed. I'm almost certain that I tested your pattern earlier and it failed - but obviously not.

Anyway, I guess that means that the regex engine is "smart enough" to know that even if it gets a match with the [012345]? - it has to "release" it to the \d if there is no 2nd digit - yes?

Replies are listed 'Best First'.
Re^5: simple pattern match ?
by Corion (Patriarch) on Mar 15, 2006 at 17:15 UTC

    Yes. The regex engine uses backtracking and marks its location whenever it has to make a decision. If the first decision doesn't work out, it backtracks to the last marked point and uses the next possible decision. The ? regex operator is such a decision point and I guess that basically, the two possibilities for a match are:

    [012345]\d
    and

    \d
    So in this case, it would not get a match when trying /[012345]\d/ against 5, so it backtracks, and tries /\d/, which works.