这个给我带来了麻烦。
假设字母:
-any lowercase or uppercase letter
-0-9 decimal digits
-_
-$
-%
我想写一个给我字符串的表达式:
-starts with a uppercase letter or one of the three symbols
-can only have at most 6 lowercase or uppercase letters
我想尝试像
这样的东西/^[a-z|_|$|%][a-z|A-Z|_|$|%]* {0,3}
但我很难跟踪"最多"案例取决于初始字符 p>
编辑:抱歉忘了示例。
_ababab <- OK
ab%$aaaa <- OK
_abababa <- NOT OK, because there is more than 6 alphabet characters
a$ababab <- NOT OK, because there is more than 6 alphabet characters
答案 0 :(得分:0)
我认为您需要添加(?=.*[A-Z]{,6})(?=.*[a-z]{,6})
答案 1 :(得分:0)
我想你想要这样的东西,
^[A-Za-z](?:[^A-Za-z]*[A-Za-z][^A-Za-z]*){5}$|^[_$%](?:[^A-Za-z]*[A-Za-z][^A-Za-z]*){6}$