8

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

  • JHMCU26809C211501 - good
  • JHMGD18508S219366 - good
  • JHMCU268091111111 - bad
  • 12345678901234567 - good
  • ASD1111111ASD2313 - bad
  • ASDIIIIIIIASDASD2 - bad
  • IIIIIIIADS1EE2345 - bad
Andrey M
  • 83
  • 1
  • 1
  • 4

2 Answers2

19

You may do negation through negative lookahead.

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

DEMO

Avinash Raj
  • 172,303
  • 28
  • 230
  • 274
0

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} )
 )+
 $