password validation - no repeating patternsmore than twice in succession

Hi experts:
I have a requirement to validate passwords using the usual criteria, but one interesting one.  I must make sure the password does not contain characters repeating more than once in a succession.  The password can only be 20 characters long.  The requirement means the following:
Legal passwords may contain: abcabc, dd, !&!&, rere

Illegal passwords: abcabcabc, ddd, !&!&!&, rerere

I hope this makes sense.  I am working in coldfusion 8.  I am trying to use a regular expression, but I think I need to do some sort of recurssion.

Any ideas?  Thanks in advance.  If you could point me in the right direction, that would be a big help.
Who is Participating?
käµfm³d 👽Connect With a Mentor Commented:
You would need to remove the look-ahead I placed in there--the (?= ...) part. The pattern you need would be:

Open in new window

Hi snix,
Try this regex:
The adobe website has an example of capturing repeating words here:

Read the section on using backreferences.

Hope this helps.
käµfm³d 👽Commented:
I am a bit confused by your requirement, so I am posting two patterns--you can pick which applies to you  :)

Both validate that the string is 20 characters.
// This will match if a series of characters
//  are found repeating twice anywhere in
//  the string (e.g. abchelloabcthereabc)

// This will match if a series of characters
//  are found repeating twice immediately in
//  succession (e.g. abcabcabc)

Open in new window

2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

snix123Author Commented:
Thank you.  I already have the 20 characters limit working.  For the second pattern, I think I would just try to use this: ^(?=.*?(.+)\1\1.*?) since I don't need to test the length here.  Can't seem to make it work without testing length, too.  

I will play around with it.  The backreferenceing doc is helping, too.
snix123Author Commented:
Thanks to all: this is looking pretty good.  
käµfm³d 👽Commented:
NP. Glad to help :)
All Courses

From novice to tech pro — start learning today.