说明
^(?=(?:[^a-z]*?[a-z]){1,8}(?!.*?[a-z]))(?=(?:[^0-9]*?[0-9]){1,8}(?!.*?[0-9]))(?=(?:[^A-Z]*?[A-Z]){1,8}(?!.*?[A-Z]))(?=(?:[^!-\/:-@[-`{-~]*?[!-\/:-@[-`{-~]){1,8}(?!.*?[!-\/:-@[-`{-~]))[a-zA-Z0-9!-\/:-@[-`{-~]{16,25}$
** 要更好地查看图像,只需右键单击图像并选择在新窗口中查看
此正则表达式将执行以下操作:
- 要求字符串长度为 16-25
- 在字符串中的任何位置都需要 1 到 8 个 a-z 字符,仅此而已
- 要求字符串中任意位置包含 1 到 8 个 A-Z 字符,仅此而已
- 在字符串中的任何位置都需要 1 到 8 个 0-9 字符,仅此而已
- 在字符串的任何位置都需要 1 到 8 个符号,仅此而已
- 允许零个空格
示例
现场演示
https://regex101.com/r/oS4mY2/2
示例文本
注意:第一个示例来自您的评论,但它包含超过 8 个小写字母,因此不匹配。
aWoeed1#fde39393aii
aWoeed1#fde39393AII
示例匹配
aWoeed1#fde39393AII
说明
NODE EXPLANATION
--------------------------------------------------------------------------------
^ the beginning of the string
--------------------------------------------------------------------------------
(?= look ahead to see if there is:
--------------------------------------------------------------------------------
(?: group, but do not capture (between 1 and
8 times (matching the most amount
possible)):
--------------------------------------------------------------------------------
[^a-z]*? any character except: 'a' to 'z' (0 or
more times (matching the least amount
possible))
--------------------------------------------------------------------------------
[a-z] any character of: 'a' to 'z'
--------------------------------------------------------------------------------
){1,8} end of grouping
--------------------------------------------------------------------------------
(?! look ahead to see if there is not:
--------------------------------------------------------------------------------
.*? any character except \n (0 or more
times (matching the least amount
possible))
--------------------------------------------------------------------------------
[a-z] any character of: 'a' to 'z'
--------------------------------------------------------------------------------
) end of look-ahead
--------------------------------------------------------------------------------
) end of look-ahead
--------------------------------------------------------------------------------
(?= look ahead to see if there is:
--------------------------------------------------------------------------------
(?: group, but do not capture (between 1 and
8 times (matching the most amount
possible)):
--------------------------------------------------------------------------------
[^0-9]*? any character except: '0' to '9' (0 or
more times (matching the least amount
possible))
--------------------------------------------------------------------------------
[0-9] any character of: '0' to '9'
--------------------------------------------------------------------------------
){1,8} end of grouping
--------------------------------------------------------------------------------
(?! look ahead to see if there is not:
--------------------------------------------------------------------------------
.*? any character except \n (0 or more
times (matching the least amount
possible))
--------------------------------------------------------------------------------
[0-9] any character of: '0' to '9'
--------------------------------------------------------------------------------
) end of look-ahead
--------------------------------------------------------------------------------
) end of look-ahead
--------------------------------------------------------------------------------
(?= look ahead to see if there is:
--------------------------------------------------------------------------------
(?: group, but do not capture (between 1 and
8 times (matching the most amount
possible)):
--------------------------------------------------------------------------------
[^A-Z]*? any character except: 'A' to 'Z' (0 or
more times (matching the least amount
possible))
--------------------------------------------------------------------------------
[A-Z] any character of: 'A' to 'Z'
--------------------------------------------------------------------------------
){1,8} end of grouping
--------------------------------------------------------------------------------
(?! look ahead to see if there is not:
--------------------------------------------------------------------------------
.*? any character except \n (0 or more
times (matching the least amount
possible))
--------------------------------------------------------------------------------
[A-Z] any character of: 'A' to 'Z'
--------------------------------------------------------------------------------
) end of look-ahead
--------------------------------------------------------------------------------
) end of look-ahead
--------------------------------------------------------------------------------
(?= look ahead to see if there is:
--------------------------------------------------------------------------------
(?: group, but do not capture (between 1 and
8 times (matching the most amount
possible)):
--------------------------------------------------------------------------------
[^!-\/:-@[-`{- any character except: '!' to '\/', ':'
~]*? to '@', '[' to '`', '{' to '~' (0 or
more times (matching the least amount
possible))
--------------------------------------------------------------------------------
[!-\/:-@[-`{-~] any character of: '!' to '\/', ':' to
'@', '[' to '`', '{' to '~'
--------------------------------------------------------------------------------
){1,8} end of grouping
--------------------------------------------------------------------------------
(?! look ahead to see if there is not:
--------------------------------------------------------------------------------
.*? any character except \n (0 or more
times (matching the least amount
possible))
--------------------------------------------------------------------------------
[!-\/:-@[-`{-~] any character of: '!' to '\/', ':' to
'@', '[' to '`', '{' to '~'
--------------------------------------------------------------------------------
) end of look-ahead
--------------------------------------------------------------------------------
) end of look-ahead
--------------------------------------------------------------------------------
[a-zA-Z0-9!-\/:-@[- any character of: 'a' to 'z', 'A' to 'Z',
`{-~]{16,25} '0' to '9', '!' to '\/', ':' to '@', '['
to '`', '{' to '~' (between 16 and 25
times (matching the most amount possible))
--------------------------------------------------------------------------------
$ before an optional \n, and the end of the
string