GetDate in a string in C #

I'm having trouble using regex to get a date in a string. Example:

 string text = "75000+ Sept.-Oct. 2004";
MatchCollection dates = Regex.Matches(text, @"[0-9]{5,}[+][\s](jan|feb|fev|mar|apr|avr|may|mai|jun|jui|jul|jui|aug|aoû|sept|oct|nov|dec)[\.][\-](jan|feb|fev|mar|apr|avr|may|mai|jun|jui|jul|jui|aug|aoû|sept|oct|nov|dec)[\.]\s[0-9]{4}", RegexOptions.IgnoreCase);

This code matches my current line, but I would like to get, in my matchcollection, “Sep 2004” and “Oct 2004” to parse it in 2 days.

If anyone has an idea, thank you very much.

+3
source share
1 answer

Check array lengths, etc. You should get an idea

 string text = "75000+ Sept.-Oct. 2004";
 MatchCollection dates = Regex.Matches(text, @"[0-9]{5,}[+][\s](jan|feb|fev|mar|apr|avr|may|mai|jun|jui|jul|jui|aug|aoû|sept|oct|nov|dec)[\.][\-](jan|feb|fev|mar|apr|avr|may|mai|jun|jui|jul|jui|aug|aoû|sept|oct|nov|dec)[\.]\s([0-9]{4})", RegexOptions.IgnoreCase);
 Console.WriteLine(dates[0].Groups[1] + " " + dates[0].Groups[3]);
 Console.WriteLine(dates[0].Groups[2] + " " + dates[0].Groups[3]);
0
source

Source: https://habr.com/ru/post/1735894/


All Articles