本文介绍了如何在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,\ n
  • 显示捕获

但是,这似乎是在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\((.+)\)

以下是替换为的文本:

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代码(vscode)

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

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

08-12 13:09