相关疑难解决方法(0)

在perl中使用正则表达式匹配的奇怪问题,备用尝试匹配

请考虑以下perl脚本:

 #!/usr/bin/perl

 my $str = 'not-found=1,total-found=63,ignored=2';

 print "1. matched using regex\n" if ($str =~ m/total-found=(\d+)/g);
 print "2. matched using regex\n" if ($str =~ m/total-found=(\d+)/g);
 print "3. matched using regex\n" if ($str =~ m/total-found=(\d+)/g);
 print "4. matched using regex\n" if ($str =~ m/total-found=(\d+)/g);

 print "Bye!\n";
Run Code Online (Sandbox Code Playgroud)

运行此后的输出是:

1. matched using regex
3. matched using regex
Bye!
Run Code Online (Sandbox Code Playgroud)

相同的正则表达式匹配一次,之后不匹配.任何想法为什么备用尝试匹配同一个字符串与相同的正则表达式在perl中失败?

谢谢!

regex perl

5
推荐指数
2
解决办法
208
查看次数

标签 统计

perl ×1

regex ×1