如何将此日期格式与正则表达式匹配? [英] How to match this date format with a regex?
本文介绍了如何将此日期格式与正则表达式匹配?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所有在这里的正则表达式大师都好,我知道您在解决我的问题方面有很多工作要做.呵呵
hi to all regex master out there, I know you have a work around with regards to my problem. hehe
02-May-2011
或
22-May-2011
或
2-May-2011
(dd-MMM-yyyy)yyyy不接受数字以外的任何其他字符
(dd-MMM-yyyy) with yyyy not accepting any other characters than digit
推荐答案
[0-9]{1,2}/[a-zA-Z]{3}/[0-9]{4}
假设月份是3个字母的版本:例如1月,2月,3月.
That's assuming that the month is a 3-letter version: eg, Jan, Feb, Mar.
更新版本以匹配对问题的更改:
Updated version to match the changes to the question:
[0-9]{1,2}-[a-zA-Z]{3}-[0-9]{4}
如前所述,它实际上不会验证日期,它只会验证字符串是否匹配以下格式: 1或2个数字,破折号,3个字母,破折号,4个数字.
As has been mentioned, this won't actually validate the date, it'll just validate that the string matches the format of: 1 or 2 numbers, a dash, 3 letters, a dash, 4 numbers.
这篇关于如何将此日期格式与正则表达式匹配?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文