首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带空格的Regexp

带空格的Regexp
EN

Stack Overflow用户
提问于 2013-01-25 18:07:52
回答 1查看 136关注 0票数 1

我有如下的regexp模式:

代码语言:javascript
复制
^[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+$

此模式应验证文档名称是否正确,如下所示的文档名称应与此模式匹配:

代码语言:javascript
复制
1207181 FINAL 12 13 12 1533

一开始--只是数字,就像id一样。

下一个空格。

下一个INV或最后一个单词。

格式为dd mm yy的下一个日期。

接下来是一些数字。

有人能帮我解决这个问题吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-01-25 19:31:39

您要搜索的是:

代码语言:javascript
复制
^(\d+)\s(INV|FINAL)\s(0[1-9]|[12]\d|3[01])\s(0[1-9]|1[0-2])\s(\d{2})\s(\d+)$

解释:

代码语言:javascript
复制
^                      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匹配。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14519525

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档