通过正则表达式从字符串中提取日期

时间:2013-11-22 13:07:27

标签: regex

我有不同的字符串,想要从该字符串中提取日期。可能吗??? 字符串的日期模式类似于

on 14th Nov. 2013  at  ||   on 30 Nov., 2012 at
on 24th Sept.2013      ||   on 7th – 9th Nov. 2012 at
on 22nd Sept. 2013.    ||   on 7th – 9th Nov. 2012  at 
on 16th -17th May 2013 at   ||  on 6th March, 2013
on 22nd March, 2013 in  ||  on 15th March 2013
on 15th March 2013

1 个答案:

答案 0 :(得分:0)

您可以使用:

[0-9]{1,2}(?:st|th|nd)?\s*(?:[–-]\s*[0-9]{1,2}(?:st|th|nd)?)?\s+(?:Jan\.|Feb\.|March|April|May|Juny|July|Aug\.|Sept\.|Oct.|Nov\.|Dec\.),?\s*[0-9]{4}

但是,我不确定月份名称是否正确缩短。