Mike Perrenoud
Mike Perrenoud

Reputation: 67898

Why isn't this inverse RegEx match working in Visual Studio?

I have a RegEx:

ConfigurationManager.ConnectionStrings.Item\(\"((?!foo).)*\"

that works in Rubular and matches the second of the two strings as expected:

ConfigurationManager.ConnectionStrings.Item("foo")
ConfigurationManager.ConnectionStrings.Item("bar")

however, if I run the same expression in Visual Studio 2005 - I get no matches. It actually should match every single instance where ConfigurationManager.ConnectionStrings.Item... exists because none of them match the word foo.

Unless of course the inverse expression doesn't work in Visual Studio.

If that's true, how would I go about getting the same result in Visual Studio 2005?

Upvotes: 0

Views: 742

Answers (1)

nhahtdh
nhahtdh

Reputation: 56809

The regex below is adapted from the syntax of regular expression for find and replace feature in Visual Studio, which is not the usual Perl-based regex syntax.

ConfigurationManager.ConnectionStrings.Item\("(~(foo).)*"

~(pattern), according to the description:

Prevent match    ~(X)    Prevents a match when X appears at this point 
                         in the expression. For example, real~(ity) matches 
                         the "real" in "realty" and "really," but not the
                         "real" in "reality."

Should work similar to how negative look-ahead (?!pattern) works.

Upvotes: 2

Related Questions