user1531557
user1531557

Reputation: 63

PHP how to check there are more than 2 running same chars in a string

checking if a string has more than running one occurrence of same character. like iiiiiiii or ssssss. maybe use preg_match but what pattern it should be?

Upvotes: 0

Views: 79

Answers (1)

Oscar Lidenbrock
Oscar Lidenbrock

Reputation: 816

Try with this regex:

$str = 'hello';
print preg_match('/([\w])\1{1,}/', $str); /*return true */

Upvotes: 3

Related Questions