Match.Result()、Match.Groups[] 正则.NET常用
来源:互联网 发布:关联规则的经典算法 编辑:程序博客网 时间:2024/05/16 04:42
string html = "<div><span>aaaa</span><a href='http://yuxnet.blog.163.com/blog/'>鏈接</a><img><input type='text' /></div>";
string pattern = "<(?<tag>[a-zA-Z]+)[^<>]*>";
System.Text.RegularExpressions.MatchCollection mc = System.Text.RegularExpressions.Regex.Matches(html, pattern);
foreach (System.Text.RegularExpressions.Match item in mc)
{
this.TextBox1.Text += item.Value;
this.TextBox1.Text += "\n";
this.TextBox2.Text += item.Result("$1");
this.TextBox2.Text += "\n";
this.TextBox3.Text += item.Groups["tag"].Value;
this.TextBox3.Text += "\n";
}?
执行上面的代码,TextBox1结果为:
<div>
<span>
<a href='http://yuxnet.blog.163.com/blog/'>
<img>
<input type='text' />
?
TextBox2结果为:
div
span
a
img
input
?
TextBox3结果为:
div
span
a
img
input
?
string pattern = "<(?<tag>[a-zA-Z]+)[^<>]*>";
System.Text.RegularExpressions.MatchCollection mc = System.Text.RegularExpressions.Regex.Matches(html, pattern);
foreach (System.Text.RegularExpressions.Match item in mc)
{
this.TextBox1.Text += item.Value;
this.TextBox1.Text += "\n";
this.TextBox2.Text += item.Result("$1");
this.TextBox2.Text += "\n";
this.TextBox3.Text += item.Groups["tag"].Value;
this.TextBox3.Text += "\n";
}?
执行上面的代码,TextBox1结果为:
<div>
<span>
<a href='http://yuxnet.blog.163.com/blog/'>
<img>
<input type='text' />
?
TextBox2结果为:
div
span
a
img
input
?
TextBox3结果为:
div
span
a
img
input
?
0 0
- Match.Result()、Match.Groups[] 正则.NET常用
- 正则--match
- match
- match
- match
- $match
- Match的正则匹配
- PYTHON-正则match
- Python 正则match
- Pytho正则表达式-match
- 正则匹配: match
- Boost正则表达式库regex常用search和match示例
- JavaScript中级 --- 正则常用方法 exec、match、replace、test、$n
- 正则表达式工具Match Tracer
- C#正则表达式Match类
- Scala-match case 正则用法
- 正则表达式匹配(re.match)
- 正则表达式match方法应用
- SQL查询所有新闻分类且关联出每个分类下的最新的一条新闻
- JQuery动态创建表单:ie下select无法下拉(firefox正常)
- 正则表达式实例大全[个人整理]
- 正则表达式匹配Html标签
- *eclipse快速打开当前工程目录浏览文件插件EasyExplorer和OpenExplorer
- Match.Result()、Match.Groups[] 正则.NET常用
- C++文件操作
- 初识HtmlParser.Net
- 纯css文本溢出省略(兼容IE6+、FF2.0+、Opera9.26+、sefari)
- MVC2 Area實現網站多級目錄
- Linq To Sql 中使用lambda表达式实现Left Join
- Linq To Sql中实现Left Join使用Linq语法与lambda表达式
- .NET操作Excel表格
- .Net创建Excel文件(插入数据、修改格式、生成图表)的方法