regular expression - password policy enforcement

Hello Experts,

I need a regular expression string that matches (1 capitol, 1 lowercase, 1 number, 1 special character)

I had this:
\A(?=[-@!$^*()~_a-zA-Z0-9]*?[A-Z])(?=[-@!$^*()~_a-zA-Z0-9]*?[a-z])(?=[-@!$^*()~_a-zA-Z0-9]*?[0-9])[-@!$^*()~_a-zA-Z0-9]{8,16}\z

which seemed to be working until I added the '#' character to the string at which point it quits. Unfortunately this problem got missed until about a week away from production so I am reaching out...

Any help appreciated!
I am using this expression with the PCRE engine.
glo-dbaAsked:
Who is Participating?
 
alainbrydenConnect With a Mentor Commented:
This regular expression seems to have everything you need. If you don't require at least 10 characters you can remove that first part:
http://davidhayden.com/blog/dave/archive/2004/09/25/501.aspx

^.*(?=.{10,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=]).*$

    * Must be at least 10 characters
    * Must contain at least one one lower case letter, one upper case letter, one digit and one special character
    * Valid special characters (which are configurable) are -   @#$%^&+=

--
Alain
0
 
alainbrydenCommented:
Well it looks like your problem might be that in the PCRE documentation, comments are delimited by the # mark. Maybe you need to escape it by using it twice? (##)
0
 
alainbrydenCommented:
I stand corrected, apparently using \# to escape the hash character should take care of it.
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
alainbrydenCommented:
Here's the man page for your reference: http://www.pcre.org/pcre.txt
The relevant section for the # problem has the header "BACKSLASH"
0
 
gremwellCommented:
By the way, you may also want to escape $ sign, otherwise Perl will expand $^ variable.
0
 
glo-dbaAuthor Commented:
Your string works fine. My string doesn't work. It may be may an inconsistency in the "regex buddy" PRCE engine.

Thank you very much!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.