正则使用的几种形态
2016-07-26 21:08
337 查看
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];
}
}
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];
}
}
相关文章推荐
- hd 2141 Can you find it?(二分)
- 后web时代,你的网站更新了https了吗?
- abp记录1
- abp记录1
- KNN算法
- HDU1502 Regular Words(DP+大数模拟)
- Eclipse Java注释模板设置详解
- 严重: Field 'id' doesn't have a default value Exception in thread "main" org.hibernate.exception.Gener
- 多媒体-FFMPEG-Anroid-采集-PCM-MP3
- POJ 2947 Widget Factory <高斯消元同余线性方程>
- Spring Boot 属性配置和使用
- STL之优先队列
- Spring-Spring框架基本配置文件解析
- UVA 11111-Generalized Matrioshkas
- Android 内存溢出解决方案(OOM)
- 【序列莫队+树状数组】BZOJ3289-Mato的文件管理
- Android TV gridview 的按键事件响应巧变 && 事件分发机制
- ajax知识点总结
- 手把手教你连接mysql数据库
- Servlet基本应用