我正在尝试为特定字符串编写一个正则表达式:要匹配的每个字符串应从数字[1-9]开始,并且可能包含或可能不包含前缀。例如:0 - not match1 - match9 - match 2: - not match3:ABC - match4:56ARD20 - match5:56ARD20(any other chars except [0-9A-Z]) - not matchA:5GTS - not match (just a digits in the first part)A1:GRT - not match (just a digits in the first part):FDE3 - not match (first part should contain only digits): - not match (empty first digital part)因此,字符串的第一部分->仅是数字(强制性)。字符串可以包含一个带后缀[0-9A-Z]的符号(:)。
2 回答
![?](http://img1.sycdn.imooc.com/545862db00017f3402200220-100-100.jpg)
一只斗牛犬
TA贡献1784条经验 获得超2个赞
正则表达式 ^[1-9]\d*(?::[A-Z\d]+)?$
可读的
^ # BOS
[1-9] \d* # Digit(s) required (can only start with 1-9
(?: # Optional group
: # Colon
[A-Z\d]+ # Upper case letters or digits
)?
$ # EOS
- 2 回答
- 0 关注
- 106 浏览
添加回答
举报
0/150
提交
取消