Alex Rivera | Logout

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

Asked 2009-08-06T17:03:45.593
18

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 have a Regex I can use to only find Url within a quoted string e.g. "Use this Url:"?

Edit

I was looking looking for a quick and dirty way to find designer text and hard coded strings that had Url in the string and change them to URL.

Edit
Report

2 Answers

9

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*.*)*$
answered 2009-08-06T17:15:27.333
6

If you just quickly want to search for a quoted string you can use the "Use Wildcards" Find Option in Visual Studio.

For example:

"*Url*"
answered 2009-09-28T10:01:21.340

Your Answer