Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要删除正则表达式中所有匹配的组。一个玩具示例是:
echo 'spam 123 ham 345 eggs' | perl -pe 's/( \d+ )/SOMETHING/g' 123 345
什么 perl 正则表达式会删除匹配组以外的所有内容?匹配的组可能比数字更复杂 - 我可以定义要匹配的组,但在组之外我可以包含任何随机字符
只需加入所有比赛即可。我不知道 Perl,但这样的事情可能会起作用:
$result = join('', $subject =~ m/\s*\d+\s*/g);