How to match all spellings of the word except one?

Viewed 67

Let's say I would like to match all spellings of the word abc except one - abc. So in a text of: abc word abC 3226 aBc aBC Abc AbC ABc ABC it would match all these abc's except for the first one - abc and not other characters in the text. Can't think of how to write this.

I tried (?i)(abc)(?!abc), (?i)(abc)^(?!abc), ^(?!abc)(?i)(abc), ^(?!abc)(?i:abc), \b(?!abc)(?i:abc)\b in notepad++, none of these work on the text above:

enter image description here

1 Answers

You did not check Match Case option and that made your regex match in a case insensitive way.

Check Match Case option and use

\b(?!abc)(?i:abc)\b

Or,

\b(?!abc)(?i)abc\b

Or, do not bother with NPP settings and use a second inline modifier or modifier group to override case insensitive options:

\b(?!(?-i)abc)(?i)abc\b
\b(?!(?-i:abc))(?i:abc)\b

See the regex demo

So, (?i) turns on case insensitivity ((?i:...) does it for a group), and (?-i) turns the case insensitivity off ((?-i:...) does it for a group).

Related