13 lines
497 B
Perl
13 lines
497 B
Perl
#!/usr/bin/perl
|
||
|
||
$txt="1234ab56";
|
||
$txt =~ /\d\d/g;
|
||
print "matched $&: ",pos $txt,"\n";
|
||
$txt =~ /\d\d/g;
|
||
print "matched $&: ",pos $txt,"\n";
|
||
$txt =~ /\G\d/g; # 强制从位移4开始匹配,无法匹配字母a,但又不允许跳过
|
||
# 所以本次\G全局匹配失败,由于没有修饰符c,指针重置
|
||
print "matched $&: ",pos $txt,"\n";
|
||
$txt =~ /\G\d/g; # 指针回到0,强制从0处开始匹配,数值1能匹配成功
|
||
print "matched $&: ",pos $txt,"\n";
|