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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

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.
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

käµfm³d 👽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


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
snix123Author Commented:
Thanks to all: this is looking pretty good.  
käµfm³d 👽Commented:
NP. Glad to help :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Regular Expressions

From novice to tech pro — start learning today.