Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Find and Replace with Regex

I want to replace C# attributes with VB.NET, which means, [Serializable] should become <Serializable>.

The pattern (\[)(.+)(\]) does find the results but I don't know how to replace the first and the last groups with the appropriate parenthesis.

I read this page, but I didn't understand how to use the curly braces for F&R, I tried to wrap the groups with it but it didn't work.

like image 327
Shimmy Weitzhandler Avatar asked Jan 19 '23 14:01

Shimmy Weitzhandler


1 Answers

If you are using the Productivity Power Tools extension from Microsoft that support normal .NET regexes, what you would put in the textbox for the replacement given your regular expression above is:

<$2>

where $2 refers to the second capture group in your regex, i.e. the text between the brackets.

Note that this only works with the Quick Find from Productivity Power Tools though. The normal find/replace in Visual Studio use another syntax altogether.

like image 176
DeCaf Avatar answered Jan 25 '23 09:01

DeCaf