简要介绍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就是一组捕获。