你给的例子,<ul class="Mlist"> 这个没有结束标志,我就根据它取后面的<ol>...</ol>了
如果有不符合的,给出例子Match m = Regex.Match(str, @"(?<=<h1>[^<]*</h1>\s*<ul\s*class=""Mlist"">)(\s*<ol>[\s\S]*?</ol>)*", RegexOptions.IgnoreCase);
if (m.Success)
{
string content = m.Value; //第一次匹配内容
MatchCollection mc = Regex.Matches(content, @"<a.*?href=""(?<url>[^""]*)""[^>]*>(?<text>[^<>]*)</a>", RegexOptions.IgnoreCase);
foreach (Match ma in mc)
{
Console.WriteLine(ma.Groups["url"].Value); //链接
Console.WriteLine(ma.Groups["text"].Value); //文字
}
}
如果有不符合的,给出例子Match m = Regex.Match(str, @"(?<=<h1>[^<]*</h1>\s*<ul\s*class=""Mlist"">)(\s*<ol>[\s\S]*?</ol>)*", RegexOptions.IgnoreCase);
if (m.Success)
{
string content = m.Value; //第一次匹配内容
MatchCollection mc = Regex.Matches(content, @"<a.*?href=""(?<url>[^""]*)""[^>]*>(?<text>[^<>]*)</a>", RegexOptions.IgnoreCase);
foreach (Match ma in mc)
{
Console.WriteLine(ma.Groups["url"].Value); //链接
Console.WriteLine(ma.Groups["text"].Value); //文字
}
}
解决方案 »
- C1FlexGrid控件如何选中一行
- [高分讨论] 如何用 webbrowser 模拟单击 Yahoo 新版邮箱的 收信按钮
- 在线等.在调用“Fill”前,SelectCommand属性尚未初始化???????
- gridview删除问题
- 全部积分球vpn拨号软件源码
- DateTimePicker.value
- 读取资源文件中的中文显示出来全是问号
- 获取添加删除程序列表
- 关于c#里asp.net的错误怎么解决呢
- 各位老大,请问:用C#开发的软件安装到用户机器上是不是要安装.NET框架啊!!我急需答案!!谢谢!!
- RowFilter 后 子集与原始数据怎样同步?高分奉上
- 我的treeview中的节点是根据数据库生成的,如何选定一个节点后添加节点,代码是如何写的
string content = 内容; string regex = "<ul[^>]+?>[\\s\\S]+?<li>\\s*<a[\\s\\S]+?href=\"(?<src>.*?)\"[\\s\\S]*?>(?<desc>[^<]+?)</a>" +
"\\s*</li";
System.Text.RegularExpressions.RegexOptions options = ((System.Text.RegularExpressions.RegexOptions.IgnorePatternWhitespace | System.Text.RegularExpressions.RegexOptions.Multiline)
| System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex(regex, options); System.Text.RegularExpressions.MatchCollection resultes = reg.Matches(content); foreach (System.Text.RegularExpressions.Match item in resultes)
{
string src = item.Groups["src"].Value;
string desc = item.Groups["desc"].Value;
}
文字用这个:">([\u4e00-\u9fa5]+)<"