How can I detect with a regex expression
if the same consonant is repeated three times or more?
My idea is to match words like tttoo
I'd personally solve this in reverse; instead of using [b-df-hj-np-tv-z]
, I'd go with the double-negative, [^\W_aeiou]
.
/([^\W_aeiou])\1\1+/i
This has a character class that uses a double negative: match anything except a non-word-character, an underscore, or a vowel. Ignoring non-ASCII vowels, only consonants can match this. Saving a match, the regex then seeks a match of that same consonant (case-insensitive), then one or more again, which brings us to 3+ consecutive consonants.