1、判断是否匹配
Regex re = new Regex("\\\\u[0123456789abcdef]{4}", RegexOptions.IgnoreCase);
re.IsMatch(InputStr);
2、使用Match判断匹配并取匹配的值
string strReg = @"((product_list).+?\})";//short开始的提取出来
Regex re = new Regex(strReg, RegexOptions.IgnoreCase);
if (re.Match(inputStr).Success)
{
sb.Append(re.Match(inputStr).Value);//获取匹配的值
}
3、匹配多组,循环匹配的组
string strReg = @"((product_list).+?\})";
Regex re = new Regex(strReg, RegexOptions.IgnoreCase);
string res;
MatchCollection mc = re.Matches(inputStr);
foreach (Match ma in mc)
{
string aa = ma.Value;
if (aa.Contains("DNH"))
{
str2=System.Text.RegularExpressions.Regex.Split(aa, ",");
res = str2[1];
}
}