if (preg_match('/(.)\1{2}/', $str))
echo "Has 3 same characters consecutively!";
The (.)
will match any character (except new lines), and the 1
will match a pattern same as the first matched group — in this case, the character we've just matched. So this RegEx will match 3 same consecutive characters.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…