[已解决问题] 获得字符串中重复出现的词(利用正则表达式)
提问时间: 2008-03-05 08:47
悬赏分: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,为什么啊?



问题补充:我输入过asdfasdf,和123123123123

最佳答案
请给出你的输入字符串.

这个表达式需要重复词连在一起,以空格分隔.
2008/3/5 9:20:05 回答者:deerchao


提问者对于答案的评价:呵呵。谢谢啊。我的知识差的太多了。请以后多多指教啊。
评论
4个月前   Ninety-Nine :
哦。原来是这样。o(∩_∩)o...。谢谢啊。
   您需要登录以后才能回答!
我的问题    我要提问


快到期问题

> 问题排行榜

有不合适内容,建议去除