正则表达式以在Visual Studio中搜索字符串中的单词 [英] Regex to search for a word in a string in Visual Studio

查看:158
本文介绍了正则表达式以在Visual Studio中搜索字符串中的单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在我的所有代码库中搜索"Url",并将其替换为"URL".如果我在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:"?

修改

我一直在寻找一种快速而又肮脏的方法来查找在字符串中包含Url的设计器文本和硬编码字符串并将其更改为URL.

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.

推荐答案

我真正需要的是:

("[^"]*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.

此正则表达式以及带有匹配大小写"和匹配整个单词"的标准查找都产生了一些字符串的结果,我希望找不到并消除其中带有"URL"的代码.

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.

这篇关于正则表达式以在Visual Studio中搜索字符串中的单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆