Negative Lookahead Regular Expression

7 posts / 0 new
Last post

I am using the information on QRegExp from and am having a bit of a problem with negative lookaheads. It seems that it is ignoring them when I use regular expressions on my news filter.

Here is the code I am using:


But it is including the words from the negative expression in my news filter.  Am I missing something?

Did you try the non-part (?

Did you try the non-part


only to see if it works?

I use this


for exclusions.

You're right. My negative

You're right. My negative lookahead wasn't working and the one you mention works great. But when I add the words I want included it doesn't return the desired results.

I've tried both




and I'm not getting the results I'm looking for. Is there a particular order or placement for the expressions?

I shortly tested this

I shortly tested this positive:


That didn't do it for me.

That didn't do it for me. Here is what I got to work in case anybody needs to use this in the future:


Hmm, I seem to be having

Hmm, I seem to be having problem with the word boundary \b. Is anyone else having problems with that escape character?

For instance, (?!.*(?:words|\bI\b|do|not|want)).*$ is different from (?!.*(?:words|I|do|not|want)).*$ in that the second one will match any word with the letter I in it but the first will only match the whole word I.

The behaviour is correct. See

The behaviour is correct. See f.e. this description.

What are you trying to achieve?
I guess it's \B you need.