in reply to Debugging Regexes
... locates the word 'hello' then if the rest of the string ...
This is your first problem: a lookahead peeks into the string, but doesn't change the position that the rest of the string will attempt to match at. You don't want a lookahead for this, but a straight match - then the rest of the pattern will correctly be tried against the rest of the string:
/^hello.../
... if the rest of the string DOES NOT contain the char 'G' followed by the char 'a' ...
A simple negative lookahead:
/ (?! # fail to match if you find ( .* # zero or more characters Ga # followed by "Ga" ) # ) /x
So your specification is satisfied simply by:
/^hello(?!.*Ga)/
Hope this helps,
Hugo
|
|---|