1、判断是否匹配 @H_403_2@
Regex re = new Regex("\\\\u[0123456789abcdef]{4}",RegexOptions.IgnoreCase);
re.IsMatch(InputStr);
2、使用Match判断匹配并取匹配的值
string strReg = @"((product_list).+?\})";//short开始的提取出来@H_403_2@ Regex re = new Regex(strReg,RegexOptions.IgnoreCase);@H_403_2@ if (re.Match(inputStr).Success)
{
sb.Append(re.Match(inputStr).Value);//获取匹配的值@H_403_2@
}
3、匹配多组,循环匹配的组@H_403_2@
string strReg = @"((product_list).+?\})";@H_403_2@
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]; } }
原文链接:https://www.f2er.com/regex/359066.html