Regex - notepad ++ - search for a string containing a string and not containing another string

I can not solve this: I have a text file with some elements, such as "user = ABname". I would like to search for all lines containing a user ID that does not start with "AB" or "ab", and I need to do this with regular exp using Notepad ++ search functionality. I tried using

user = ^[ab] 

but actually does not work as expected.

I have to find all of this:

 user = CDname1 user = cdname2 user = acname3 user = xbname4 

but not

 user = abname1 user = ABname2 
+4
source share
4 answers

Try using a negative look ahead:

 user = (?![aA][bB]).* 

You misunderstand how the character class works. The character class - [ab] corresponds to only one character, of all those present inside [ and ] . Thus, it will correspond to either a or b . I will not match ab in the sequence. Basically, the images [ab] coincides with a|b .

+6
source

You need to use a negative view, for example:

 ^user = (?![Aa][Bb]) 
+5
source

Try: ^user = ([aA][^bB].*|[^a].*)

It searches for user = , then either: a , followed by something that is not b , or anything that does not start with a .

0
source

You can use this:

  user = (?:[^a]|a(?!b))\S+ 

(do not check case insensitive, but check the regex field :)

0
source

Source: https://habr.com/ru/post/1494371/


All Articles