php - Regex to check if a character occurs more than X times in a string -
what regex check if character occurs more 2 times in string? example: "aab" allowed, not "aaa" or "aaba". is there way make match on valid inputs (when there less 3 repeating characters) preg_match() function returns 1 valid input (with less 3 repeating characters) , else 0? thanks! this regex find character repeats 3 times (or more because have hit 3 more). (.)\1{2} regex demo: https://regex101.com/r/wmupww/1 php usage: foreach(array('aaa', 'aab') $string) { if(preg_match('/(.)\1{2}/', $string)) { echo $string . ' doesnt match :(' . "\n"; } else { echo $string . ' matches'. "\n"; } } php demo: https://eval.in/672382