How do you reference a capture group with regex find and replace in Visual Studio 2012, 2013, 2015, and VS Code

To find and replace in VS 2012 and VS 2015 you do the following:

  • Surround with (), display capture with $1, $2, $n

Example (thanks to syonip)

In the find options, make sure ‘use regular expressions’ is checked, and put the following as the text to find:

_platformActions.InstallApp\((.+)\)

And the following as the text to replace it with:

this.Platform().App($1).Install()

Note: As SLaks points out in a comment below, the change in regex syntax is due to VS2012 switching to the standard .Net regex engine.

Note: Another commenter pointed out that this works in Visual Studio Code (vscode) as well

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)