正则表达式以匹配日期格式DD-MM-YYYY和DD / MM / YYYY [英] Regex to match date formats DD-MM-YYYY and DD/MM/YYYY

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

问题描述

我正在处理Sublime Text 3中的一个大型文本文件,该文件具有以行分隔的条目。我正在寻找一个正则表达式,将:

I'm working in Sublime Text 3 with a large text file that has entries separated by lines. I'm looking for a regular expression that will:


  • 匹配出现在 DD-MM-YYYY中的条目格式

  • 匹配以 DD / MM / YYYY 格式显示的条目

  • Match entries that appear in the DD-MM-YYYY format
  • Match entries that appear in the DD/MM/YYYY format

如果两者都太复杂,那么仅第一个示例就可以。

If both would be too complicated, then just the first example will do.

我还没有'我并没有为实现这种正则表达式做任何事情,因为说实话,它远远超出了我的了解,而且我也不知道从哪里开始,而查看类似的答案来处理日期格式的正则表达式也可以证实我的怀疑。

I haven't done anything to work towards such a regex, because it's honestly way above my knowledge of it and I wouldn't know where to start, and looking at similar answers dealing with regex validation of date formats confirms those suspicions for me.

在此先感谢您的帮助。

Thanks in advance for any help.

推荐答案

此模式适用于您的条件。

This pattern will work for your conditon. Strictly not allowed month to date and vice versa.

^([0]?[1-9]|[1|2][0-9]|[3][0|1])[./-]([0]?[1-9]|[1][0-2])[./-]([0-9]{4}|[0-9]{2})$

此模式将与这些匹配格式:(日期,月份,年份)

This pattern will match these formats: (Date, Month, Year)

25.04.2017  
02.04.2017  
2.4.2017  

25/04/2017  
5/12/2017  
15/2/2017  

25-04-2017  
6-10-2017  
16-5-2017  

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

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