I would like an expression that strictly searches for a capital letter at the start, followed by a combination of upper or lower in the middle, followed by at least 1 digit. Such as 'Tedsmith28'. I think that's what your suggestion does do Martin (?) but when I ran it across a 20Mb source data it took over 10 minutes and hasn't returned anything. Maybe I had coded it wrong though.
Mine did more:
It checked for the presence of the 3 (upper,lower,digit) in any order, and with any others inbetween.
For what you describe:
^[A-Z].*[a-z].*[0-9]$
or more optimized
^[A-Z][^a-z]*^[a-z].*[0-9]$
- First must be upper
- then anything can follow
- somewhere in the middle must be a lower
- after the lower anything can follow
- at the end must be a digit
Actually you can optimize my initial one
^[^a-zA-Z0-9]* (
( [A-Z] [^a-z0-9]* ( ([a-z].*?[0-9]) | ([0-9].*? [a-z]) ) ) |
( [a-z] [^A-Z0-9]* ( ([A-Z].*?[0-9]) | ([0-9].*? [A-Z]) ) ) |
( [0-9] [^a-zA-Z]* ( ([a-z].*?[A-Z]) | ([A-Z].*? [a-z]) ) )
)
And the [^a-zA-Z0-9] is only needed if it can start with .,-=^*&...
But do keep the ^ at the very start.
Out of interest, compare the time for the optimized as above, and a none greedy version:
^[^a-zA-Z0-9]*? (
( [A-Z] [^a-z0-9]*? ( ([a-z].*?[0-9]) | ([0-9].*? [a-z]) ) ) |
( [a-z] [^A-Z0-9]*? ( ([A-Z].*?[0-9]) | ([0-9].*? [A-Z]) ) ) |
( [0-9] [^a-zA-Z]*? ( ([a-z].*?[A-Z]) | ([A-Z].*? [a-z]) ) )
)
This will require less backtracing in the reg-ex engine
[^a-zA-Z0-9]* skip all none chars e.g £$%^&-.,
Then it hits one of the 3 sub expressions (one of the 3 lines). The password that is tested must (after all ,.35433) have either an upper, a lower, or a digit
example 1st line:
$$ABC-Xdef!1
The $$ is skipped
The ABC is matched by [A-Z]+
Now all can be skiped that is NOT lower or digit [^a-z0-9]* / That includes' skipping further upper
The inner or ("|") sud expression is hit
- either a lower [a-z], followed whatever, and eventually a digit
- or a digit [0-9], followed whatever, and eventually a lower
FYI, I have (fro memory)
MyRegExpr.Exec := 'YourExpressionAbove';
you mean MyRegExpr.Expression ?