C#에서 일치와 점점 일치 똑같은 반면 정규식정규식 내가 C# .NET을 사용하여 다음 패턴과 일치하는 것을 시도하고
^([[a-z][A-Z]]*):([[a-z][A-Z][0-9],]*)$
샘플 문자열
Student:Tom,Jerry
을
발견되지 루비에서 작동합니다 (Rubular을 사용하여 확인). 어떤 아이디어가 C#에서 작동하지 않는 이유는 무엇입니까?
코드 블록
public static KeyValuePair<string, IList<string>> Parse(string s)
{
var pattern = new Regex(@"(\w*):([\w\d,]*)");
var matches = pattern.Matches(s);
if (matches.Count == 2)
{
return new KeyValuePair<string, IList<string>>(matches[0].Value, matches[1].Value.Split(','));
}
throw new System.FormatException();
}
정말 익숙하지 않은데, 어떤 상황에서 벗어날 필요가 있습니까? – Sturm
범위가 잘못되어 있습니다. '^ ([a-zA-Z] *) : ([a-zA-Z0-9,] *) $' – hazzik
[RegExr] (http://gskinner.com/RegExr /)는 이런 종류의 일에 좋은 도구입니다. 여기에 귀하의 [working] (http://regexr.com?31kih)과 [not working] (http://regexr.com?31kik)의 예가 있습니다. – RichardTowers