简体   繁体   中英

How to get a regular expression based on the following constraints

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,ie, { | , * , () }

  1. It should start with a digit or English alphabet.
  2. There should be at least one lower case, one upper case and one digit.
  3. There should be at least one special character from the set {@,$,#,%,&}.
  4. 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)* )

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"...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM