in reply to Did regex match fail because of "end of string"?

Hmmmm....

I would've thought that if a regular expression match failed, it was because it hit the end of the string without finding a match. Other than program crashes, what else would cause the match to fail?

...roboticus

  • Comment on Re: Did regex match fail because of "end of string"?

Replies are listed 'Best First'.
Re^2: Did regex match fail because of "end of string"?
by ikegami (Patriarch) on Oct 16, 2007 at 20:03 UTC

    I believe the OP wants to know if there was a time when the engine reached the end of the string after starting a match.

    For /a\d+b/,

    "a123b\n" -> match "a123\n" -> incomplete match "a123c\n" -> no match
      ikegami:

      Ah! That interpretation certainly makes sense. (I found it hard to reconcile my interpretation of the question with moritz' experience.)

      ...roboticus

Re^2: Did regex match fail because of "end of string"?
by Joost (Canon) on Oct 16, 2007 at 20:02 UTC
    If the regex is anchored to the beginning of the string, it could fail without reaching the end. Otherwise, as far as I can imagine it would have to match every available substring* up to the end of the string.

    * if the match is at least N characters long the match will fail if any of the (last - N) .. last characters of the string don't match and the subsequent characters don't have to be tested. Anyway this is equivalent to running into the end of string.

      Right, all matches in the tokenizer will be anchored to pos with \G.