2010-03-08 2 views
3

정규식을 사용하여 문자열에 날짜를 가져 오는 데 문제가 있습니다. 예 :GetDate 문자열을 C#

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); 

이 코드는 현재의 내 캐릭터와 일치한다하지만 난이 날짜에서 그것을 분석하기 위해 내을 MatchCollection "2004년 9월"와 "2004년 10월"에서 좀하고 싶습니다.

누구나 아이디어가 있으면 감사드립니다.

답변

0

확인 배열 등의 길이 당신은 아이디어를

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

감사를 많이 얻어야한다, 나는 내 정규 표현식의 각 그룹을 얻을 수 있습니다 몰랐다. – Doncho