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就是一组捕获。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM