以下似乎匹配,
有人可以解释为什么吗?Perl正则表达式 - 为什么正则表达式/[0-9.]+(,,)/匹配逗号
我想匹配多个数字或点,以逗号结尾。
123.456.768,
123,
.,
1.2,
但这样做以下意外打印,
太
my $text = "241.000,00";
foreach my $match ($text =~ /[0-9\.]+(\,)/g){
print "$match \n";
}
print $text;
# prints 241.000,
# ,
更新:
逗号,因为匹配: In list context, //g returns a list of matched groupings, or if there are no groupings, a list of matches to the whole regex
作为here.定义
您不需要转义逗号;如果你不打算捕捉它们,你不需要这些parens。你想打印/ caputre究竟是什么? – NullUserException
不知道这里的问题是什么。你的捕获组包含一个转义的逗号(不确定反斜杠对Perl中的逗号有什么影响),所以我希望这会返回一个逗号作为捕获的字符串。 –
请编辑你的问题来完成你的想法 - “我怎么能匹配更多的长度的数字比,哪个”...? – maerics