Extract a format of date from a string

Total Post:89


 2115  View(s)
Rate this:

I need to extract a date of birth from a given string. The format is always "ddMMMyy" (for example "22NOV83").

The problem is that there could be other chars before and after the dob. possible inputs are : "DOB: 22NOV83", "CUSTOMER A DOB: 22NOV", "22NOV83 BLA BLA"

I think that by using this Regex:


I can check if a string mathces a date , But how to check if a part of a string mathces a date and than extract it ?

Any help would be appreciated.

  1. Re: Extract a format of date from a string

    Hi Takeshi,

    var extractedDates = new List<DateTime>();
      foreach (var s in inputs) {
        var m = Regex.Match(s, @"(\d{2}[A-Za-z]{3}\d{2})");
        if (m.Groups.Count == 1) {
          // No match
        try {
        } catch (FormatException) {
          // Regex matched but something else was wrong, i.e. 98ALS98

      Modified On Apr-04-2018 04:33:22 AM


Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.