A regular expression that will match if there is no repetition

I would like to create a regex that matches the password if there is no character repeating 4 or more times.

I came up with a regular expression that will match if a character or group of characters is repeated 4 times:

(?:([a-zA-Z\d]{1,})\1\1\1)

Is there a way to match only if the string does not contain repetitions? Have I tried the approach suggested in Regular Expression to match a string that does not contain a word? as I thought this would do a combination of positive / negative hits. But so far I have not found a working example.

By repetition, I mean any number of characters in any line of a line

Example - Should Not Match

aaaaxbc

abababab

x14aaaabc

-

abcaxaxaz

( 4 , , )

+4
2

, .

^(?:(?!(?<char>[a-zA-Z\d]+)\k<char>{3,}).)+$ 

^(?:(?!([a-zA-Z\d]+)\1{3,}).)+$ 

REY

+1

Nota Bene: , .

-----

Python:

import re

pat = '(?:(.)(?!.*?\\1.*?\\1.*?\\1.*\Z))+\Z'

regx = re.compile(pat)

for s in (':1*2-3=4@',
          ':1*1-3=4@5',
          ':1*1-1=4@5!6',
          ':1*1-1=1@',
          ':1*2-a=14#a~7&1{g}1'):
    m = regx.match(s)
    if m:
        print m.group()
    else:
        print '--No match--'

:1*2-3=4@
:1*1-3=4@5
:1*1-1=4@5!6
--No match--
--No match--

, , , , , , .
, -.

0

All Articles