Chinaunix首页 | 论坛 | 博客
  • 博客访问: 855451
  • 博文数量: 253
  • 博客积分: 6891
  • 博客等级: 准将
  • 技术积分: 2502
  • 用 户 组: 普通用户
  • 注册时间: 2010-11-03 11:01
文章分类

全部博文(253)

文章存档

2016年(4)

2013年(3)

2012年(32)

2011年(184)

2010年(30)

分类: Python/Ruby

2011-10-12 16:03:45

A quantifier in a pattern means to repeat the preceding item a certain number of times.
You’ve already seen three quantifiers: *, +, and ?. But if none of those three suits your
needs, just use a comma-separated pair of numbers inside curly braces ({}) to specify
exactly how few and how many repetitions are allowed.
So the pattern /a{5,15}/ will match from 5 to 15 repetitions of the letter a. If the a
appears three times, that’s too few, so it won’t match. If it appears five times, it’s a
match. If it appears 10 times, that’s still a match. If it appears 20 times, just the first 15
will match, since that’s the upper limit.

/(fred){3,}/ match more than 3 times.
/a{5,15}/ [5-15];
/a{5} / just 5;
* <=> {0,}
+ <=> {1,}
? <=> {0,1}
阅读(366) | 评论(0) | 转发(0) |
0

上一篇:Named Captures %+

下一篇:General Quantifiers {}

给主人留下些什么吧!~~