I need help in creating regex based on the following constraints for creating a password. [This is for a course assignment]
Note : I can't use extended regular expression. I need to use core regex,i.e, { | , * , () }
- It should start with a digit or English alphabet.
- There should be at least one lower case, one upper case and one digit.
- There should be at least one special character from the set {@,$,#,%,&}.
- Any sequence of 3 or more digits should not be repetition of same digit.
This is my working so far : \
A = { English letters **union** Digits } \
B = { Lowercase letters **union** Digits } \
C = { Uppercase letters **union** Digits } \
D = { Special characters } \
Regex = A(A)* ( B(B)* C(C)* D(D)* )
CodePudding user response:
I can think of a way to solve all the requirements excluding the last one:
A = { English letters **union** Digits }
B = { Lowercase letters }
C = { Uppercase letters }
D = { Digits }
E = { Special characters }
F = { Union of all allowed characters }
Then you need to spell out all the possible permutations:
A (BB* CC* DD* EE* | BB* CC* EE* DD* | BB* DD* CC* EE* | BB* DD* EE* CC* | ...) F*
But if you want to add the "no more than three identical digits" rule, I don't see a way around spelling out all those possibilities as well (and do it 24 times for each permutation), which makes it clear why this is not something you want to do with "core regex"...