在任何给定字符串中查找日期

时间:2014-04-09 14:39:57

标签: c# regex date

我需要在任何给定的字符串中找到格式为dd / MMMM / yyyy的日期。我的带有正则表达式的代码会查找日期,如果它不在句子中。有人可以帮我一个新的正则表达式来找到任何给定字符串中的日期。

 public static bool FoundDate(String Date)
    {
        Regex date = new Regex(@"\b((31(?!\ (Feb(ruary)?|Apr(il)?|June?(Sep(?=\b|t)t?|Nov)(ember)?)))|((30|29)(?!\ Feb(ruary)?))|(29(?=\ Feb(ruary)?\ (((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)))))|(0?[1-9])|1\d|2[0-8])\ (Jan(uary)?|Feb(ruary)?|Ma(r(ch)?|y)|Apr(il)?|Ju((ly?)|(ne?))|Aug(ust)?|Oct(ober)?|(Sep(?=\b|t)t?|Nov|Dec)(ember)?)\ ((1[6-9]|[2-9]\d)\d{2})$");
        Match m = date.Match(Date);
        if (Date != null && m.Success)
            return date.IsMatch(Date);
        else return false;
    }

在字符串上失败:

     string StringBirth = "Once upon a time there was a girl, born on 15 August 1988.";

提前谢谢

0 个答案:

没有答案