PracticeDev/study_perl/re/8re.pl

13 lines
497 B
Perl
Raw Normal View History

2022-12-20 17:31:11 +08:00
#!/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";