in reply to A Regex simple Question

Your regex says "an a, followed by arbitrary characters, followed by arbitrary characters that don't start with ab, then a b".

This means that the (?!ab) will always find a position where the next position is not ab.

Knowing this, the solution is not so hard:

/^a(?!.*ab).*b$/

Replies are listed 'Best First'.
Re^2: A Regex simple Question
by ikegami (Patriarch) on Sep 06, 2007 at 16:11 UTC
    That will fail (false negative) for a000ab.
      You are right. That can easily be ammended by changing it to /^a(?!.*ab.).*b$/.

      Regexes are hard, sometimes. Especially corner cases ;)