为了账号安全,请及时绑定邮箱和手机立即绑定

数字,字母和:的正则表达式

数字,字母和:的正则表达式

PHP
宝慕林4294392 2021-05-13 14:10:21
我正在尝试为特定字符串编写一个正则表达式:要匹配的每个字符串应从数字[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 回答

?
一只斗牛犬

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


查看完整回答
反对 回复 2021-05-28
  • 2 回答
  • 0 关注
  • 106 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信