日期表达式的正则表达式,用于2月验证 [英] Regular expression for date expression with february validation

查看:111
本文介绍了日期表达式的正则表达式,用于2月验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试过这个表达但是它不会采取2010年之前的日期,如果你能告诉我我犯了哪个错误,这将是一个很大的帮助。



我尝试过:



/ ^(((((0?[1-9])|([1 -2] [0-9])|(3 [0-1])) - (([JJ] [AA] [NN])|([mm]的[AA] [RR])|([mm]的[ AA] [YY])|([JJ] [UU] [11])|([AA] [UU] [gG的])|([OO] [CC] [TT])|([日] [EE] [CC])))|(((0 [1-9])|([1-2] [0-9])|(30)) - (([AA] [PP] [RR])?| ([JJ] [UU] [NN])|([SS] [EE] [PP])|([NN] [OO] [VV])))|(((0 [1-9])| (1 [0-9])|(2 [0-8])) - ([FF] [EE] [BB]))) - (20(([13579] [01345789])|([2468] [ 1235679]))))|(((((0 [1-9])|([1-2] [0-9])|(3 [0-1])) - (([JJ] [ AA] [NN])|([mm]的[AA] [RR])|([mm]的[AA] [YY])|([JJ] [UU] [11])|([AA] [UU] [gG的])|([OO] [CC] [TT])|([日] [EE] [CC])))|(((0 [1-9])|([1-2] [ 0-9])|(30)) - (([AA] [PP] [RR])|([JJ] [UU] [NN])|([SS] [EE] [PP])|([ NN] [OO] [VV])))|(((0 [1-9])|(1 [0-9])|→(2 [0-9])) - ([FF] [EE] [bB]))) - (20(([13579] [26])|([2468] [048])))))$ /

I tried this expression but it wont take dates which are before the year 2010 it would be a big help if you can tell me where i have made the mistake.

What I have tried:

/^((((((0?[1-9])|([1-2][0-9])|(3[0-1]))-(([jJ][aA][nN])|([mM][aA][rR])|([mM][aA][yY])|([jJ][uU][lL])|([aA][uU][gG])|([oO][cC][tT])|([dD][eE][cC])))|(((0?[1-9])|([1-2][0-9])|(30))-(([aA][pP][rR])|([jJ][uU][nN])|([sS][eE][pP])|([nN][oO][vV])))|(((0?[1-9])|(1[0-9])|(2[0-8]))-([fF][eE][bB])))-(20(([13579][01345789])|([2468][1235679]))))|(((((0?[1-9])|([1-2][0-9])|(3[0-1]))-(([jJ][aA][nN])|([mM][aA][rR])|([mM][aA][yY])|([jJ][uU][lL])|([aA][uU][gG])|([oO][cC][tT])|([dD][eE][cC])))|(((0?[1-9])|([1-2][0-9])|(30))-(([aA][pP][rR])|([jJ][uU][nN])|([sS][eE][pP])|([nN][oO][vV])))|(((0?[1-9])|(1[0-9])|(2[0-9]))-([fF][eE][bB])))-(20(([13579][26])|([2468][048])))))$/

推荐答案

/


不要这样做:

使用RegEx检查模式,然后使用一小段代码来处理包括闰年在内的所有特殊情况。

使用最后一个链接查看RegEx的漂亮图表。



只是一些有趣的链接来帮助构建和调试RegEx。

以下是RegEx文档的链接:

perlre - perldoc.perl.org [ ^ ]

以下是帮助构建RegEx并调试它们的工具的链接:

.NET Regex Tester - Regex Storm [ ^ ]

Expresso正则表达式工具 [ ^ ]

这个显示RegEx是一个很好的图表,这真的很有帮助至了解RegEx的作用:

Debuggex:在线可视正则表达式测试器。 JavaScript,Python和PCRE。 [ ^ ]
Don't do this :
Use the RegEx to check the pattern, then use a little piece of code to handle all particularities including leap years.
Use the last link to see a nice graph of your RegEx.

Just a few interesting links to help building and debugging RegEx.
Here is a link to RegEx documentation:
perlre - perldoc.perl.org[^]
Here is links to tools to help build RegEx and debug them:
.NET Regex Tester - Regex Storm[^]
Expresso Regular Expression Tool[^]
This one show you the RegEx as a nice graph which is really helpful to understand what is doing a RegEx:
Debuggex: Online visual regex tester. JavaScript, Python, and PCRE.[^]


检查:示例:正则表达式匹配有效日期 [ ^ ]


这篇关于日期表达式的正则表达式,用于2月验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆