Regex: How to retrieve all lines containing strA but not strB in Visual Studio

Viewed 9967

How can I retrieve all lines of a document containing "strA", but not "strB", in the Visual Studio search box?

5 Answers

For Visual Studio 2010 (and previous versions):

The Visual Studio search box has its own, bizarre version of regex syntax. This expression works as requested:

^~(.*strB).*strA

^ matches the beginning of a line. (Typically for a text editor, there's no "multiline" option; ^ and $ always match at line boundaries.)

. matches any character except a newline. (Not so typically, there appears to be no "single-line" or "dot-all" mode that lets dots match newlines.)

~(...) is the "prevent match" construct, equivalent (as far as I can tell) to the negative lookahead ((?!...)) used by the other responders.

Related