regex to match repeated consonant

后端 未结 6 1886
悲&欢浪女
悲&欢浪女 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:46

    This is about the shortest regex I could think of to do it:

    (?i)([b-z&&[^eiou]])\1\1+
    

    This uses a regex character class subtraction to exclude vowels.
    I didn't have to mention "a" because I started the range from "b".
    Using (?i) makes the regex case insensitive.

    See a live demo.

提交回复
热议问题