4

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

4 Answers 4

6

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.

Sign up to request clarification or add additional context in comments.

Comments

5

You need to use a negative lookahead, such as:

^user = (?![Aa][Bb])

Comments

0

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

It looks for user = then either: a followed by anything that's not b or "anything that doesn't start with an a.

Comments

0

You can use this:

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

(don't check the case insensitive box, but check the regex box:)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.