简体   繁体   English

如何根据以下约束获取正则表达式

[英]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.任何 3 个或更多数字的序列不应是同一数字的重复。

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"...但是如果你想添加“不超过三个相同数字”的规则,我看不出有办法把所有这些可能性都拼出来(并且对每个排列都做 24 次),这就很清楚为什么会这样了不是你想用“核心正则表达式”做的事情......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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