正则表达式以匹配日期格式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