【发布时间】:2018-01-11 15:32:31
【问题描述】:
我有大量的降价文件。在这些文件中,我想将某些### Response 替换为### ResponseNew
### Response
I don't want to replace this Response above to ResponseNew since it is not following Example
## Example
### Request
123{}```
### Response
I want to replace this Response above to ResponseNew since it is following Example
所以我尝试使用
## Example[^]+### Response
替换为
$&New
当我在 RegExr website 中进行测试时,此方法有效。
但是,使用Sublime查找替换,却显示错误:
字符类声明中的 [ 或 [^ 不匹配。发生错误 在解析正则表达式片段时:'# Response>>>HERE>>>'。 在正则表达式中 ## Example[^]+### 响应
我还尝试在this 之后的终端中使用 Perl,
find . -type f -exec perl -p -i -e "s/## Example[^]+### Response/$&New/g" {} \;
它显示:
正则表达式中不匹配的 [;标记为
如何正确编写正则表达式以便匹配?谢谢
【问题讨论】:
-
Perl 中不存在
[^]成语。 -
Regexr 不支持 Perl 正则表达式语法。它只对测试 JavaScript 正则表达式有用。
-
我可以使用任何其他正则表达式来代替 [^] 吗?谢谢
-
(?s:.),/./s。使用带点的s修饰符。[^]在 ECMAScript 标准中的意思是 not nothing = any char。 -
OTOH,Perl 将
[^]视为[^\]...