如何找到同一字符的多次出现? 像这样的东西:
$maxRepeat = 3;
"pool" passes
"poool" don't
我需要它适用于任何角色,所以我想我必须转义像 . 这样的特殊字符。和\
我必须转义哪些字符?
除了 php.net 上的那个之外,您还知道对 preg_match
regexp 的任何好的引用吗?
最佳答案
您使用 quantifiers为此
preg_match("/p(o){1,3}ls/",$string);
摘录:
The following standard quantifiers are recognized:
1. * Match 0 or more times
2. + Match 1 or more times
3. ? Match 1 or 0 times
4. {n} Match exactly n times
5. {n,} Match at least n times
6. {n,m} Match at least n but not more than m times
我最喜欢的学习Perl Regularular Expressions 的资源是时间荣幸camel book .但如果你手边没有,this site还不错。
关于php - 使用 preg_match 匹配同一字符的多次出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1637941/