我有如下的regexp模式:
^[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或最后一个单词。
格式为dd mm yy的下一个日期。
接下来是一些数字。
有人能帮我解决这个问题吗?
发布于 2013-01-25 19:31:39
您要搜索的是:
^(\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由于13的原因,它不会与1207181 FINAL 12 13 12 1533匹配。
https://stackoverflow.com/questions/14519525
复制相似问题