In Visual Studio, when I search within a selection, I want to replace the first instance (or second, third, etc.) of a match per line using regular expressions. How would I do this?
Search and replace
foo1 = foo1; foo2 = foo2; ... foo20 = foo20;
into the following.
foo1 = bar1; foo2 = bar2; ... foo20 = bar20;
CHANGE: The default keyboard shortcut for “Multiline Find/Replace” was Ctrl+Alt+F but it was not applied because this shortcut was already taken by “F# Interactive”. So, the new default shortcut is Ctrl+M, Ctrl+F.
In Visual Studio 2012, capture groups and backreferences are used just like in C#. You can capture them with common parenthesis, and backreference them with $0, $1, etc. Hope it helps!
Note that the syntax $1
is used for find-replace, but \1
is used for backreferences in the search string.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With