By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,347 Members | 1,313 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,347 IT Pros & Developers. It's quick & easy.

Regex Help! (unique numbers)

P: 1
Hey would anyone be able to help me create a regex for Python that has a minimum of 3 characters and a max of 5 characters? the first 3 characters have to be unique and the last two optional characters can be any characters.

Once again, the last two characters can be anything! (even the same as one of the first 3 characters)

This is what I have right now: ^(?:(\w)(?!.*\1)){3}\w{0,2}$

The only problem with this regex is that it does not allow the last two characters to be the same as any of the first 3. (eg. pfaab doesnt work when it should)

Can anyone help please?
May 21 '14 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.