请考虑以下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中失败?
谢谢!