The first is lookbehind, not look. To understand what is going on here, add up what the regular expression says:
(?<![A|a])A #An A that is not preceded by A, a, or a literal | .?; #Any number of characters followed by ;
Now consider your input, AAstring :
A
So lookbehind works, it just doesn't do what you think it does. I think you want something like this:
^(?![Aa]{2})A.*?;
This binds itself to the beginning of the line, so you know where the lookahead will look. Here is what it means:
^ #Beginning of the line (?![Aa]{2}) #"The following string must not start with two As in a row, regardless of case" A.*?; #Capital A followed by anything followed by ;
You can also try
\b(?![Aa]{2})A.*?;
if your target is not at the very beginning of the line.
Please note that this is actually the same as ^A(?![Aa]).*?; or \bA(?![Aa]).*?; but it may be easier to understand.
source share