简体   繁体   English

Perl-正则表达式转义失败

[英]Perl - Regex escaping failure

Following Perl onliner fails, the regex is ok, though. 但是,在Perl onliner失败之后,可以使用正则表达式。 Something is wrong with the esacping, but I can't finger out what. 偷偷摸摸是有问题的,但我无法指出。 Can someone help me out? 有人可以帮我吗? I'm on Linux/Bash. 我在Linux / Bash上。

perl -pi -e '(?<=\.zip).*?(hren)|(^\")|(^\r\n|^\n)|(^New).*?(\")|(\,\s)' file

This is the error message: 这是错误消息:

Unmatched ) in regex; marked by <-- HERE in m/<=\.zip) <-- HERE .*/ at -e line 1.

As @mpapec pointed out, you forgot to add m// to make the statement into a regex. 正如@mpapec所指出的,您忘记添加m//来使该语句成为正则表达式。 So why do you get a regex error if it isn't being treated as a regex? 那么,如果不将其视为正则表达式,为什么会收到正则表达式错误呢?

Perl thinks you're trying to use the ?PATTERN? Perl认为您正在尝试使用?PATTERN? format for pattern matching, see perlop . 模式匹配的格式,请参见perlop It looks at: 它看起来:

?<=\.zip).*?

Attempts to interpret the bit between ?..? 尝试解释?..?之间的位 as a regex and correctly identifies the unmatched ) . 作为正则表达式并正确标识不匹配的)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM