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#.
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#.
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
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.