C#正则表达式匹配

1、匹配所有带括号的字符串

string s = "aaaa(bbb)ccc(ddd)eeee";
string pattern = "\\(\\w+\\)";
或者写成

string pattern = @"\(\w+\)";

MatchCollection results = Regex.Matches(s, pattern);

results[0].Value=(bbb)
results[1].Value=(ddd)

测试地址
http://tools.jb51.net/regex/javascript

 

猜你喜欢

转载自www.cnblogs.com/zhaogaojian/p/9192564.html
今日推荐