-5

I'd like to extract an invoice date from the text of an invoice.

I'll have a string with the entire invoice text, and I don't know where the date is in the text or how the date is formatted.

How would I attack this problem? I am using C#.

ericdc
  • 11,217
  • 4
  • 26
  • 34
SimonHL
  • 175
  • 5
  • 14

2 Answers2

2

How about something like this? It would only handle one specific format but the regex can be adjusted for other formats.

Regex rg = new Regex(@"[01]?\d[/-][0123]?\d[/-]\d{2}");
Match m = rg.Match(string);
m.ToString();

Here is a question with a bunch of date regexes that may help. Regular Expression to match valid dates

Community
  • 1
  • 1
ericdc
  • 11,217
  • 4
  • 26
  • 34
0

Learn and use regular expressions - >

Regex Cheat Sheet for C#

Regex Hero A good place to test your regex

Regex Matching How to get the matched value back from Regex in C#

You'll need to hande different format possibilities.

Jonesopolis
  • 25,034
  • 12
  • 68
  • 112