[regex-coach] Greetings and a puzzle

Frank lists at frankmarion.com
Tue Sep 27 12:27:26 UTC 2005


Hi, I'm new to the list. I was looking for a nice regex list, and found 
this one. Let me start off with an interesting puzzle that someone sent me

A programmer wants to test a password, and he wants to do it in ONE 
expression. Here are the criteria for a well formed password

1) Minumum of eight characters in length
2) Two words [a-z_] are required
3) Two digits [0-9] are required.

I've been working on this all night, and what I've come up with is the 
following

An alpha and a numeric will always be side to side. This will catch it

         [a-z_][0-9]|[0-9][a-z_]

<group alpha fb number OR number fb alpha>

The problem is that there might be a run of non-matches before, or 
following, or between each of these pairs. One might be inclined to say 
"Ah! Then the solution is to add {2,}. Not so, because then it would return 
the match of a1a1 but not a1xa1. It would catch a1 then 1x (it's the 
closest match).

This is the crux of the problem, as I've been able to figure so far.

It's a tough but interesting puzzle. I'd be interested in hearing your options.





Frank Marion     lists at frankmarion.com      Keep the signal high.






More information about the regex-coach mailing list