加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

正则使用的几种形态

发布时间:2020-12-14 04:21:06 所属栏目:百科 来源:网络整理
导读:1、判断是否匹配 Regex re = new Regex("\u[0123456789abcdef]{4}",RegexOptions.IgnoreCase); re.IsMatch(InputStr); 2、使用 Match 判断匹配并取匹配的值 string strReg = @"((product_list).+?})";//short开始的提取出来 Regex re = new Regex( strRe

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]; } }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读