。我使用正则表达式 \#include \"[a-z\.h]+\" 来查找包含语句。但我想知道如何构建替换正则表达式。\#include \<[a-z\.h]+\> 不起作用,也不会;它将语句 #include "......" /> 。我使用正则表达式 \#include \"[a-z\.h]+\" 来查找包含语句。但我想知道如何构建替换正则表达式。\#include \<[a-z\.h]+\> 不起作用,也不会;它将语句 #include "......"> 。我使用正则表达式 \#include \"[a-z\.h]+\" 来查找包含语句。但我想知道如何构建替换正则表达式。\#include \<[a-z\.h]+\> 不起作用,也不会;它将语句 #include "......" />
我正在尝试使用 Visual Studio 2005 中的查找和替换功能将所有 #include "whatever.h"
替换为 #include <whatever.h>
。我使用正则表达式 \#include \"[a-z\.h]+\"
来查找包含语句。但我想知道如何构建替换正则表达式。
\#include \<[a-z\.h]+\>
不起作用,也不会;它将语句 #include "whatever.h"
替换为 #include <[a-z.h]+>
。我应如何构建替换正则表达式以保持 whatever.h
原样?
对于之前 Visual Studio 2012 的版本:
当我这样做时它可以工作:
找到 include "{[a-zA-Z]+\.h}"
,
替换为 include <\1>
。
与您的问题最相关的部分是大括号 {}
和反向引用 \1
:\n
引用搜索表达式中大括号指示的第 n 个组。
适用于 Visual Studio 2012 和up:
从 VS2012 开始使用 .NET Framework 正则表达式。所以它应该是:
找到 include "([a-zA-Z]+\.h)"
,
替换为 include <$1>
。
https://i.stack.imgur.com/GzQPV.jpg
这是我的用例,我需要找到所有这样的 html 注释
<!--begin::Info-->
<!--End::Info-->
这是我用的
(()|('.+?'))
我希望它对某人有帮助
[a-zA-Z0-9_]
捕获更多文件名。