Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am not able to solve this: I have text file with some entries like "user = ABname". I would like to search for all the lines containing user id not beginning with "AB" or "ab" and I need to do it with a regular exp using the search functionality of Notepad++. I have tried using

user = ^[ab]

but actually is not working as expected.

I should find all these:

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

but not

user = abname1
user = ABname2
like image 285
d82k Avatar asked Dec 21 '22 02:12

d82k


2 Answers

Try using negative look ahead:

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

You are misunderstand how a character class works. The character class - [ab] matches only one character, out of all present inside [ and ]. So, it will match either a or b. I won't match ab in sequence. Basically
[ab] is same as a|b.

like image 183
Rohit Jain Avatar answered Feb 16 '23 00:02

Rohit Jain


You need to use a negative lookahead, such as:

^user = (?![Aa][Bb])
like image 36
Phylogenesis Avatar answered Feb 15 '23 23:02

Phylogenesis