PracticeDev/study_perl/re/8re.pl

13 lines
497 B
Perl
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/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";