C#中正则表达式Regex的match和matches方法

简要介绍C#中正则表达式Regex的match和matches方法       
            string s = "aaaa(bbb)aaaaaaaaa(bb)aaaaaa";
            string pattern = "\\(\\w+\\)";
            Match result = Regex.Match(s,pattern);
            MatchCollection results =  Regex.Matches(s,pattern);
然后你会看到
result.Value = {(bbb)};
results[0].Value = {(bbb)};
results[1].Value = {(bb)};
也就是match会捕获第一个匹配。而matches会捕获所有的匹配。
——————————————————
matchcollection result = Regex.matches(s)
match类型就是一个单独的捕获,matchcollection就是一组捕获。

posted on 2013-03-15 15:26  董珍  阅读(8617)  评论(0编辑  收藏  举报

导航