On Thu, Dec 13, 2001 at 02:29:14PM +0100, Kim Schulz wrote:
> How short kan you make a program (oneliner?) that:
>
> * checks if a password is 5 characters long or more
> * checks if the password contains at least 3 alpha chars (a-zA-Z)
> * checks if the password contains at least 2 numbers (0-9)
Well, the first condition is redundant. :-)
How about
for ($password) {die if 3>y/a-zA-z//c || 2>y/0-9//c}
?
It's interesting to try & do it as a single regex. The shortest
I've found is:
/(?=[a-z].*[a-z].*[a-z]).*\d.*\d/
(This seems to be one of those cases where using a lookahead assertion
can make the regex a lot shorter, even though you're not actually
looking ahead. The (?=...) is effectively being used as an
intersection operator; and it's known that adding an intersection
operator to a basic regex language allows some expressions to be
exponentially shortened.)
.robin.