我有这样的正则表达式:
^[a-zA-Z0-9]+\s(INV|FINAL)\s([0,1]?\d{1}\s(([0-2]?\d{1})|([3][0,1]{1}))\s(([1]{1}[9]{1}[9]{1}\d{1})|([2-9]{1}\d{3})))(\s{1})\d+$
此模式应验证文档名称是否正确 像这样的文档名称应与此模式匹配:
1207181 FINAL 12 13 12 1533
一开始 - 只是数字,它就像是id。
下一个空格。
下一个INV或FINAL字。
格式为dd mm yy的下一个日期。
接下来的一些数字。
有人可以帮我解决这个问题吗?
答案 0 :(得分:0)
您正在搜索:
^(\d+)\s(INV|FINAL)\s(0[1-9]|[12]\d|3[01])\s(0[1-9]|1[0-2])\s(\d{2})\s(\d+)$
说明:
^ start at the beginning of the string
(\d+) capture any digit
\s one whitespace
(INV|FINAL) captrue INV or FINAL
0[1-9] a 0 and a digit from 1 to 9
[12]\d a 1 or a 2 and a digit
3[01] a 3 and a 0 or a 1
(0[1-9]|[1-2]\d|3[01]) capture a digit from 01 to 31
(0[1-9]|1[0-2]) capture a 0 and a digit from 1 to 9 or a 1 and a digit from 0 to 2 | so capture a digit from 01 to 12
(\d{2}) capture two digits
$ stop at the end of the string
由于1207181 FINAL 12 13 12 1533
。
13
匹配