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