Regex Unmatched(在正则表达式中;标记为<;——在此处替换用一半()

Regex Unmatched(在正则表达式中;标记为<;——在此处替换用一半(),regex,perl,Regex,Perl,此文件包含一行文本: <p>detached, (disconnected, unfastened</p> 当我跑的时候 perl-pE'/\K.*(?=)/@words=split(/,/,$&)$new_string=join“,”,map{qq||}@words;$|=~s/$&/$new_string/g;'a.txt 它给出了以下错误: 无与伦比的(在正则表达式中;标记为我同意Håkon;最后的替换是解释这个输入流中的括号,而不是找到与它匹配的括号。

此文件包含一行文本:

<p>detached, (disconnected, unfastened</p>   
当我跑的时候

perl-pE'/\K.*(?=)/@words=split(/,/,$&)$new_string=join“,”,map{qq||}@words;$|=~s/$&/$new_string/g;'a.txt
它给出了以下错误:


无与伦比的(在正则表达式中;标记为我同意Håkon;最后的替换是解释这个输入流中的括号,而不是找到与它匹配的括号。你不能只打印/发出你的$new_字符串吗?

上下文:
s/$&/$new_字符串/g
:你可能需要引用
$&
的内容,即
s/\Q$&\e/$new_字符串/g
,有关更多信息,请参阅谢谢@HåkonHægland,它工作得很好。:)wowIndeed,$newæu字符串没问题。我想我太困惑了……谢谢@Harlan的解释。
regex
就是这样……尽管我喜欢它。:)同意;regex有时是一个熊,但在学习过程结束后非常有用。Perl对regex的实现真是太棒了。
<p><a href="entry://detached">detached</a>, <a href="entry://(disconnected">(disconnected</a>, <a href="entry://unfastened">unfastened</a></p>
perl -pE'/<p>\K.*?(?=<\/p>)/; @words=split(/, /, $&); $new_string=join ", ", map {qq|<a href="entry://$_">$_</a>|} @words; $_=~s/$&/$new_string/g;' a.txt
perl -pE's{<p>\K.*?(?=<\/p>)}{join ", ", map {qq|<a href="entry://$_">$_</a>|} split(/, /, $&)}eg' a.txt