vscode 和 Visual Studio 之间的正则表达式差异
从...开始
line1
line2
查找:^(.+)$
替换:“$1”,
在 vscode 中它按预期工作,结果是
"line1",
"line2",
在工作室里,似乎不起作用,导致
"line1
",
"line2
",
哪一个是正确的?我假设是 vscode。
TL;DR: Use ^(.*[^\r\n])
匹配没有 EOL 字符的整行。
根据Docs:
Purpose |
Expression |
Example |
Match any single character (except a line break) |
. |
a.o matches "aro" in "around" and "abo" in "about" but not "acro" in "across" |
Anchor the match string to the end of a line |
\r?$ |
car\r?$ matches "car" only when it appears at the end of a line |
Anchor the match string to the end of the file |
$ |
car$ matches "car" only when it appears at the end of the file |
然而,由于某种原因,其中一些似乎并不成立(即,.
匹配换行符并且.$
与结尾匹配any line)。以下所有模式将从行首到行尾匹配包括 EOL 字符: ^.+
, ^.+$
, ^.+\r?$
.
我之前在 VS2017 中注意到过这种行为,我不确定为什么会发生这种情况,但我可以使用如下方法来解决它:
^(.*[^\r\n])
注意:您还可以删除捕获组并替换为"$0",
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)