I'm having some trouble using regular expression to get 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 is matching with my current string but i would like to get in my matchcollection, "Sept 2004" and "Oct 2004" in order to parse it in 2 datetime.
If anyone have any idea, thanks a lot.
Check the lengths of the array, etc. You should get the 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]);
精彩评论