我怎样才能找到同一个字符的多次出现?就像是:
$maxRepeat = 3;
"pool" passes
"poool" don't
我需要这个适用于任何角色,所以我想我必须转义特殊字符,如 . 和 \
我必须逃避哪些角色?
preg_match
除了 php.net 上的 regexp 之外,您还知道有什么好的参考吗?
我怎样才能找到同一个字符的多次出现?就像是:
$maxRepeat = 3;
"pool" passes
"poool" don't
我需要这个适用于任何角色,所以我想我必须转义特殊字符,如 . 和 \
我必须逃避哪些角色?
preg_match
除了 php.net 上的 regexp 之外,您还知道有什么好的参考吗?
你为此使用量词
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
找到了,我需要的是
if(preg_match('/(.)\1/', $t)) 返回真;
这对于 $t = 'aa' 返回 true;// 任何字符
if(preg_match('/(.)\1\1/', $t)) 返回真;
这对于 $t = 'aaa' 返回 true;// 任何字符
等等
/.{1,2}/ # 2 is limit, 1 to have at least one character
任何重复多次的字符,如果您$amxRepeate
是 int,则必须格式化您的正则表达式。