I am working on creating an ECMAScript (JavaScript) flavored regex to evaluate the complexity of my password based on specific criteria:
Characters Used Password Strength Length
ABC abc 123 #$& WEAK ...
1 x 1-5 ...
2 x 1-5
3 x 1-7
4 x 1-5
5 x x 1-4
6 x x 1-4
7 x x 1-4
8 x x 1-4
9 x x 1-4
10 x x 1-4
11 x x x 1-4
12 x x x 1-3
13 x x x 1-4
14 x x x 1-4
15 x x x x 1-3
Therefore, passwords like 2
, ABCD
, 0123456
, abCd
, aA#
, etc. should be considered weak. Passwords that are longer while meeting the specified criteria e.g., 012345678
, aA1#
, should not.
My current intricate regex pattern (organized by groups according to the above table) looks something like this:
/^(([A-Za-z&*@\^}\]\\):,$=!><–{[(%+#;\/~_?.]{1,3})|([a-z0-9&*@\^}\]\\):,$=!><–{[(%+#;\/~_?.]{1,4})|([A-Z0-9&*@\^}\]\\):,$=!><–{[(%+#;\/~_?.]{1,4})|([a-zA-Z0-9]{1,4})|([a-z]{1,5})|([A-Z]{1,5})|([0-9]{1,7})|([&*@\^}\]\\):,$=!><–{[(%+#;\/~_?.]{1,5}))$/
Matches rows in the above table: 12
/([A-Za-z&*@\^}\]\\):,$=!><–{[(%+#;\/~_?.]{1,3})/
Matching rows: 14, 9
/([a-z0-9&*@\^}\]\\):,$=!><–{[(%+#;\/~_?.]{1,4})/
Matching rows: 13, 10, 7
/([A-Z0-9&*@\^}\]\\):,$=!><–{[(%+#;\/~_?.]{1,4})/
Matching rows: 11, 8, 6, 5
/([a-zA-Z0-9]{1,4})/
Matching rows: 2
/([a-z]{1,5})/
Matching rows: 1
/([A-Z]{1,5})/
Matching rows: 3
/([0-9]{1,7})/
Matching rows: 4
/([&*@\^}\]\\):,$=!><–{[(%+#;\/~_?.]{1,5})/
Is there a way to reuse the special characters I defined inside []
[&*@\^}\]\\):,$=!><–{[(%+#;\/~_?.]
, so that I don't have to list them out within each individual group?