Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 413
Jeff Avatar asked Aug 06 '09 17:08

Jeff


People also ask

How do you search for a word in regex?

To run a “whole words only” search using a regular expression, simply place the word between two word boundaries, as we did with ‹ \bcat\b ›. The first ‹ \b › requires the ‹ c › to occur at the very start of the string, or after a nonword character.

How do I search for a word in Visual Studio?

Ctrl + Shift + F – Find in Solution Sometimes you want to search across your entire solution. You can double-click each item in the “Find Results” window to navigate to that instance of the search term you searched for.

How do you use regex in VSCode search?

Vscode has a nice feature when using the search tool, it can search using regular expressions. You can click cmd+f (on a Mac, or ctrl+f on windows) to open the search tool, and then click cmd+option+r to enable regex search. Using this, you can find duplicate consecutive words easily in any document.


1 Answers

What I really ended up needing was:

("[^"]*Url[^"]*")

And thanks to the tip from tghw who pointed out the :q shortcut in Visual Studio equates to:

(("[^"]*")|('[^']*'))

I realized I needed to use the first portion to find only the double quoated strings I was looking for.

Both this regex and a standard find with 'Match case' and 'Match whole word' yielded results with some strings I was hoping to not find but eliminated the code with 'Url' in it.

like image 180
Jeff Avatar answered Oct 01 '22 17:10

Jeff