Regex to search for a word in a string in Visual Studio

前端 未结 5 1460
梦毁少年i
梦毁少年i 2021-02-04 04:02

I need to search all of my codebase for \"Url\" and replace it with \"URL\". If I search for Url in Visual Studio I also get all my variables with \"Url\" in it.

Anyone

5条回答
  •  盖世英雄少女心
    2021-02-04 04:24

    Visual Studio has a "quoted string" operator :q. If you search for :qUrl with 'Use: Regular expressions' and 'Match case' on, it should find all instances of "Url" only in strings.

    Update: The above is incorrect. :q just searches for a quoted string, but you can't put anything into it. My testing was just showing cases that looked correct, but were just coincidentally correct. I think instead, you want something like:

    ^(:q*.*)*(("[^"]*Url[^"]*")|('[^']*Url[^']*'))(:q*.*)*$
    

提交回复
热议问题