如何在 Visual Studio 2012、2013、2015 和 VS Code 中使用正则表达式查找和替换引用捕获组 [英] How do you reference a capture group with regex find and replace in Visual Studio 2012, 2013, 2015, and VS Code

本文介绍了如何在 Visual Studio 2012、2013、2015 和 VS Code 中使用正则表达式查找和替换引用捕获组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我意识到有很多关于此的问题,但我发现没有一个特别提到他们所指的 VS 版本.由于缺少这些重要信息,我仍然无法成功使用我找到的答案.最常见的是

I realize there are a ton of questions about this, but none that I found specifically referenced which VS version they referred to. With that important information lacking, I still was unable to successfully use the answers I found. The most common was

  • 用{}包围,用1、2、 显示捕获
  • Surround with {}, display capture with 1, 2,

但是,这似乎是在 Visual Studio 中进行正则表达式查找和替换的旧方法,并且在 VS 2012 中不起作用.

However, that seems to be the old method of doing regex find and replace in Visual Studio, and it does not work in VS 2012.

推荐答案

要在 VS 2012 和 VS 2015 中查找和替换,请执行以下操作:

To find and replace in VS 2012 and VS 2015 you do the following:

示例(感谢 syonip)

Example (thanks to syonip)

在查找选项中,确保选中使用正则表达式",并将以下内容作为要查找的文本:

In the find options, make sure 'use regular expressions' is checked, and put the following as the text to find:

_platformActions.InstallApp((.+))

以及以下作为替换它的文本:

And the following as the text to replace it with:

this.Platform().App($1).Install()

注意:正如 SLaks 在下面的评论中指出的那样,正则表达式语法的变化是由于 VS2012 切换到标准 .Net 正则表达式引擎.

Note: As SLaks points out in a comment below, the change in regex syntax is due to VS2012 switching to the standard .Net regex engine.

注意:另一位评论者指出这也适用于 Visual Studio Code (vscode)

Note: Another commenter pointed out that this works in Visual Studio Code (vscode) as well

这篇关于如何在 Visual Studio 2012、2013、2015 和 VS Code 中使用正则表达式查找和替换引用捕获组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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