XML正则表达式中DD-MM-YYYY日期格式的正则表达式是什么? [英] What is the Regular Expression for DD-MM-YYYY date format in XML regex?

查看:167
本文介绍了XML正则表达式中DD-MM-YYYY日期格式的正则表达式是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道日期 dd-mm-yyyy 格式的正则表达式。规则是



如果·month·是4,6,9或11之一,不超过28,则·day·value必须不超过30如果·月·是2·······································································································不是100。



我想在xsd中的xml正则表达式中。



接受 - 29-02-2000,31-05-2013,30-04-2012



拒绝 - 29-02-1900,31-04-2013,30-02-2000

解决方案

我实际上有这个正则表达式,我做了一个与我的一个朋友的竞争一段时间!



以下是我的朋友,约20%更快:

  ^(?! 00)((([0-2] \d | 3 [01]) - ( 0 [13578] | 1 [02])|([0-2] \d | 30) - (0 [469] | 11)|([01] \d | 2 [0-8]) -  02 )-\\\\\\\\\,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,; {2}(?!00))([048] | [13579] [26]))$ 

虽然这一个是最短的(适合twitter,这是我的挑战):

$($($($)$($)$($($) (00)?$)| [13579](?= [26](00)?$)))|(?!29-02))\d | 30 | 31(? - (0 [1] | 11))) - (0 [1-9] | 1 [012]) - \d {4} $

请注意,根据gregorian日历,两个正则表达式将无法验证 yyyy = 0000 ,这不是有效的一年。



两个正则表达式都没有lookbehinds和条件,因为它必须在javascript中工作。



编辑: / p>

由于您需要使用XML,因此我修改了第一个正则表达式,只需要稍微修改即可摆脱困境。

 ((0 [1-9] | [1-2] \d | 3 [01]) - (0 [13578] | 1 [02 ])|([0-2] \d | 30) - (0 [469] | 11)|(0 [1-9] | 1\d | 2 [0-8]) -  02) \\ d {4} |(0 [1-9] | [12] \d)-02  - ((0)] [008] []]))
/ pre>

我希望这对您有用。


I want to know the regex for date dd-mm-yyyy format. And the rule is

The ·day· value must be no more than 30 if ·month· is one of 4, 6, 9, or 11, no more than 28 if ·month· is 2 and ·year· is not divisible by 4, or is divisible by 100 but not by 400, and no more than 29 if ·month· is 2 and ·year· is divisible by 400, or by 4 but not by 100.

I wanted to do in xml regex in my xsd.

Accept-- 29-02-2000, 31-05-2013, 30-04-2012

Reject-- 29-02-1900, 31-04-2013, 30-02-2000

解决方案

I actually had this regex lying around, I made it a while back as a competition with a friend of mine!

The following is my friend's, and about 20% faster:

^(?!00)((([0-2]\d|3[01])-(0[13578]|1[02])|([0-2]\d|30)-(0[469]|11)|([01]\d|2[0-8])-02)-\d{4}|([01]\d|2\d)-02-(([02468][048]|[13579][26])(?=00)|\d{2}(?!00))([02468][048]|[13579][26]))$

While this one is the shortest (fits on twitter, which was my challenge):

^(?!(00|30-02))(((?=.+(?!00)([02468](?=[048](00)?$)|[13579](?=[26](00)?$)))|(?!29-02))[012]\d|30|31(?!-(0[2469]|11)))-(0[1-9]|1[012])-\d{4}$

Note that both regexes will fail to validate for yyyy = 0000, it's not a valid year, according to the gregorian calendar.

Both regexes are free of lookbehinds and conditionals, as it had to work in javascript.

EDIT:

Since you need this for XML, I've modified the first regex a bit, it only needed slight modification to get rid of the lookaround.

((0[1-9]|[1-2]\d|3[01])-(0[13578]|1[02])|([0-2]\d|30)-(0[469]|11)|(0[1-9]|1\d|2[0-8])-02)-\d{4}|(0[1-9]|[12]\d)-02-(([02468][048]|[13579][26])00|(\d{2}([02468][48]|[2468][048]|[13579][26])))

I hope this works for you.

这篇关于XML正则表达式中DD-MM-YYYY日期格式的正则表达式是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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