perl中while修饰符/c参数

Perl正则表达式实战
本文通过两个Perl脚本示例介绍了如何使用正则表达式匹配数字和字符'e'的位置,并探讨了/c修饰符的作用,即在匹配失败后是否重置位置指针。
[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";
}

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的位置


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值