regex to match repeated consonant

后端 未结 6 1790
悲&欢浪女
悲&欢浪女 2021-02-04 03:28

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

6条回答
  •  难免孤独
    2021-02-04 03:52

    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.

提交回复
热议问题