这个给我的任务带来麻烦。正则表达式 - 限制字符串中的字符数量
假设的字母:
-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}
,但我在跟踪“最多”情况时遇到问题,具体取决于初始角色
编辑:遗忘的例子。
_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
你能解释一下这个'只能有最多6小写字母或大写字母? – 2014-09-05 03:23:22
删除出现在角色类中的'|'符号。 – 2014-09-05 03:24:02
我认为这意味着字符串中不能包含6个以上的小写字母或6个大写字母,包括第一个字母。 – 2014-09-05 03:24:52