PracticeDev/study_perl/re/7re.pl

14 lines
500 B
Raku
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
$name="123ab456";
$name =~ m/\d\d/g; # 第一次匹配,匹配成功后记下位移
print "matched string: $&, position: ",pos $name,"\n";
$name =~ m/\d\d/g; # 第二次匹配,匹配成功后记下位移
print "matched string: $&, position: ",pos $name,"\n";
# 匹配失败的时候正则匹配操作会返回假所以可以作为if或while等的条件语句
$name="123ab456";
while($name =~ m/\d\d/g){
print "matched string: $&, position: ",pos $name,"\n";
}