Regular expression to match string without repeated characters

后端 未结 2 1240
无人及你
无人及你 2021-01-22 11:49

I\'m looking for a simple regular expression to match the string where no repeated characters. Example:

  • JHMCU26809C211501 - good
相关标签:
2条回答
  • 2021-01-22 12:45

    If its a duplicate 3 or more times in a row, this is the fastest
    way to do it. (no phony demo provided)

    ^(?:(.)(?!\1{2}))+$

     ^ 
     (?:
          ( . )                         # (1)
          (?! \1{2} )
     )+
     $
    
    0 讨论(0)
  • 2021-01-22 12:46

    You may do negation through negative lookahead.

    ^(?!.*(\w)\1{3,}).+$
    

    DEMO

    0 讨论(0)
提交回复
热议问题