regex to match repeated consonant

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

    You can use capture groups with back-references. This will capture repeating symbols:

    /(
       ([\w])        ## second group is just one symbol
       \2            ## match symbol found in second groups
       \2+           ## match same symbol one or more times
    )/x              ## x is just to allow inner comments
    

    But not all regexp engines support back-references.

提交回复
热议问题