Shimmy Weitzhandler
Shimmy Weitzhandler

Reputation: 104811

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.

Upvotes: 4

Views: 2428

Answers (2)

andrey.tsykunov
andrey.tsykunov

Reputation: 2916

Find what: \[{Serializable}\]

Replace with: <\1>

Upvotes: 1

DeCaf
DeCaf

Reputation: 6116

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.

Upvotes: 8

Related Questions