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}
阅读(370) | 评论(0) | 转发(0) |