悬赏分:5 浏览:259 次
这个是我的类里的一个方法
目的是利用正则表达式获得字符串中重复出现的词。
public static ArrayList GetRepeatString(string input)
{
ArrayList myList = new ArrayList();
System.Text.RegularExpressions.MatchCollection matches = System.Text.RegularExpressions.Regex.Matches(input, @"\b(?<word>\w+)\s+(\k<word>)\b", System.Text.RegularExpressions.RegexOptions.Compiled | System.Text.RegularExpressions.RegexOptions.IgnoreCase);
if (matches.Count != 0)
{
foreach (Match match in matches)
{
myList.Add(match.Groups["word"].Value);
}
return myList;
}
else
{
return myList = null;
}
}
输入的字符串明明有重复字符,却matches.Count=0,为什么啊?
|
4个月前 Ninety-Nine : 哦。原来是这样。o(∩_∩)o...。谢谢啊。 |