Syntax for regular expression search and replace.

Category: visual studio editor

Question

KevinBurton on Thu, 09 Aug 2012 14:48:46


I would like to search and change instance like:

(string.Compare(testingConnections[i].Configuration, "CommerceServerCatalogConnectionString", StringComparison.OrdinalIgnoreCase) == 0)

to

testingConnections[i].ConfigurationEquals("CommerceServerCatalogConnectionString", StringComparison.OrdinalIgnoreCase)

So this involves regular expressions and it seems that VS's idea of regular expressions differ from the regular expressions used the System.Text.RegularExpression. I need to understand how VS matches a pattern, saves it in a variable and uses it in the replace expression. Like

With "normal" regular expressions I would search for the pattern like:

^\(string\.Compare\(\s*(?<Variable>[^,]+),\s*(?<String>[^,]+),\s*(?<Comparison>[^)]+)\)\s*==\s*0\)

And replace with

${Variable}.Equals(${String}, ${Comparison})

But I don't understand how this translates to the regular expressions that VS uses. Any ideas?

Thank you.

Replies

Abhijit Annaldas on Fri, 24 Aug 2012 17:40:30


Hi,

Refer this:

http://msdn.microsoft.com/en-us/library/2k3te2cs.aspx

http://msdn.microsoft.com/en-us/library/139eef4h.aspx

Regards.