[oracle@localhost ~]$ cat tmpperl01
#!/usr/bin/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";
}
#!/usr/bin/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";
[oracle@localhost ~]$ cat tmpperl02
#!/usr/bin/perl
$_ = "The year 1752 lost 10 days on the 3rd of September";
while (/(\d+)/cg)
{
print pos($_),"\n";
}
print pos($_)."---","\n";
while (/e/cg)
{
print pos($_),"\n";
}
print pos($_)."---","\n";
[oracle@localhost ~]$ ./tmpperl01
13
21
35
---
3
6
33
43
46
49
---
[oracle@localhost ~]$ ./tmpperl02
13
21
35
35---
43
46
49
49---
#增加/c修饰符在匹配失败后不重置pos的位置
本文通过两个Perl脚本示例介绍了如何使用正则表达式匹配数字和字符'e'的位置,并探讨了/c修饰符的作用,即在匹配失败后是否重置位置指针。
874

被折叠的 条评论
为什么被折叠?



