开发者

Regular expression: same character 3 times

开发者 https://www.devze.com 2023-03-29 15:41 出处:网络
I want a regular expression (in php) to this (same character 3 times): aa => false aaa 开发者_JS百科=> true

I want a regular expression (in php) to this (same character 3 times):

aa => false
aaa 开发者_JS百科=> true
baaa => true
aaab => true
aaaaaab => true
baaab => true
babababa => false

For any character, not only 'a' and 'b'.


You can use back-references within a regex

/(.)\1\1/


Try this regular expression:

(.)\1{2}


This will do the job :

/(.)\1\1/
0

精彩评论

暂无评论...
验证码 换一张
取 消