## 增加/c修饰符在匹配失败后不重置pos的位置,例如
C:\Documents and Settings\Administrator>perl
$_ = "The year 1752 lost 10 days on the 3rd of September";
while (/(\d+)/g)
{
print pos($_),"\n";
}
print pos($_),"\n";
while (/e/g)
{
print pos($_),"\n";
}
print pos($_),"\n";
^D
13
21
35
3
6
33
43
46
49
C:\Documents and Settings\Administrator>perl
$_ = "The year 1752 lost 10 days on the 3rd of September";
while (/(\d+)/gc)
{
print pos($_),"\n";
}
print pos($_),"\n";
while (/e/gc)
{
print pos($_),"\n";
}
print pos($_),"\n";
^D
13
21
35
35
43
46
49
49
阅读(682) | 评论(0) | 转发(0) |