Complex regex with preg_match_all()
Posted on 2012-08-13
I've been handed a request to enforce a criteria for a password policy.
I will the be the first to say regular expressions are not my strong suit. So, while this may not be as complex as it seems, it most certainly is to me.
The request is:
two of a capital, special character, or number.
I understand the individual checks:
It's how to combine them and create the AND/OR that slips past me.
I considered doing it by keeping track of the individual results and doing a comparison afterward, but it occurred to me there must be a way to do it in one expression.
So, my question is - is there a way to do this in one expression and, if so, how?
Alternately, would it be cleaner to check the $subject individually and compare the results afterwards?
I am trying desperately not to break the rules by asking more than one question with this question, but finding it extremely difficult. The reason is if an Expert with regular expressions says "do it individually" then there is no reason to pursue the other option. If the best approach is to combine the checks into one expression, of course this is the route I would like to pursue, and learn from.
Thank you in advance.