---
title: "Extract a format of date from a string"  
description: "Extract a format of date from a string"  
author: "Takeshi Okada"  
published: 2014-03-06  
updated: 2014-03-06  
canonical: https://www.mindstick.com/forum/1981/extract-a-format-of-date-from-a-string  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# Extract a format of date from a string

I need to [extract](https://www.mindstick.com/forum/12883/how-to-extract-sub-string-between-two-string-pattern-using-javascript-jquery) a [date](https://yourviews.mindstick.com/story/3869/propose-day-2024-exciting-date-ideas-for-you-and-your-partner) of birth from a given [string](https://www.mindstick.com/articles/1527/string-split-in-c-sharp). The [format](https://www.mindstick.com/forum/162083/how-to-convert-ost-files-into-pst-format) is always "ddMMMyy" (for example "22NOV83").

The [problem](https://yourviews.mindstick.com/view/81399/tackling-the-problem-of-unemployment-during-corona-pandemic) is that there could be other chars before and after the dob. possible inputs are : "DOB: 22NOV83", "[CUSTOMER](https://www.mindstick.com/articles/325839/how-to-improve-your-business-level-of-customer-service) A DOB: 22NOV", "22NOV83 [BLA](https://yourviews.mindstick.com/view/88035/who-are-balochistan-liberation-army-bla) BLA"

I think that by using this [Regex](https://www.mindstick.com/forum/160352/how-to-use-regex-in-javascript-for-pattern-matching):

^\d{2}[a-zA-Z]{3}\d{2}$

I can [check if](https://www.mindstick.com/forum/12878/how-to-check-if-an-asp-dot-net-file-upload-control-has-a-file-in-jquery) 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.

## Replies

### Reply by Pravesh Singh

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      continue;    }    try {      extractedDates.Add(DateTime.Parse(m.Groups[0].Value));    } catch (FormatException) {      // Regex matched but something else was wrong, i.e. 98ALS98    }  }
```


---

Original Source: https://www.mindstick.com/forum/1981/extract-a-format-of-date-from-a-string

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
