[英]perl sed escaping quantifiers from a regex
Having trouble removing quantifiers and meta characters from a regex with sed. 无法使用sed从正则表达式中删除量词和元字符。 To complicate matters the code is intended to be used within a eval.
为了使事情复杂化,该代码打算在评估中使用。
$word_check = "about\s*[\w\s]+";
$word_check =~ s/\\\[.+\\\]//g;
$$word_count[$#$word_count + 1] += () = $word_check =~ /(\w+)\s*/g;
Word_check is a copy of a regex. Word_check是正则表达式的副本。 Want to reduce the regex to only the words it is to match.
想要将正则表达式简化为仅要匹配的单词。 Using a regex to do so.
使用正则表达式执行此操作。 Then count the words and save the result in a array.
然后计算单词数并将结果保存在数组中。 The reason behind the choice is the regex is apart of several and when working with a match ($&) the words are removed.
选择背后的原因是正则表达式是少数几种,当使用匹配项($&)时,单词会被删除。 From a eval.
从一个评估。 The code below is intended as a string.
下面的代码旨在作为字符串。
for ( my \$i = 0; \$i < \$\$ref_word_count[\$R]; \$i++ ) {
\$temp_str =~ s/^\\w+\\s*//;
}
OK Found the answer. 确定找到答案。 Just needed to break up the sed statement some and see the square brackets as a character alone.
只需要将sed语句分解一些,并将方括号视为一个单独的字符。
$word_check =~ s/i$//;
$word_check =~ s/[\.\+]//g;
$word_check =~ s/\\[sdwSWD]//g;
$word_check =~ s/[[]//g;
$word_check =~ s/[]]//g;
$word_check =~ s/[*]//g;
$word_check =~ s/[?]//g;
Probably this helps 可能有帮助
\\Q quote (disable) pattern metacharacters till \\E
\\ Q引用(禁用)模式元字符,直到\\ E
\\E end either case modification or quoted section, think vi
\\ E结束大小写修改或引用部分,请考虑vi
See perldoc perlre 参见perldoc perlre
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.