14 lines
500 B
Raku
14 lines
500 B
Raku
#!/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";
|
||
}
|