在Visual Studio中搜索和替换 [英] Search and replace in Visual Studio

查看:256
本文介绍了在Visual Studio中搜索和替换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Visual Studio中,当我在选择中进行搜索时,我想使用正则表达式替换每行匹配项的第一个实例(或第二个,第三个等).我该怎么办?

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 do this?

搜索并替换

foo1 = foo1;
foo2 = foo2;
...
foo20 = foo20;

进入以下内容.

foo1 = bar1;
foo2 = bar2;
...
foo20 = bar20;

推荐答案

Visual Studio 2010和更早版本中,使用带有反向引用的正则表达式

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

Visual Studio的正则表达式与我所学的完全不同.花了我一些时间找出正确的答案.

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

搜索

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

替换为

\1\2 = bar\2

后向引用由tagging使用花括号{foo}来完成. :d+\d+

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

在此处详细了解VS RegEx

这篇关于在Visual Studio中搜索和替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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