Search and replace in Visual Studio

后端 未结 6 817
遥遥无期
遥遥无期 2020-12-29 03:52

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

6条回答
  •  天涯浪人
    2020-12-29 04:07

    In Visual Studio 2010 and earlier, use regular expressions with back references

    Visual Studio's regular expressions are completely different from what I've learned. Took me some time to figure out the correct answer.

    Search for

    {foo}{:d+} = \1\2
    

    Replace with

    \1\2 = bar\2
    

    Back references are done by tagging with curly braces {foo}. :d+ is the same for \d+

    Read more about VS RegEx here

提交回复
热议问题