正则表达式提取html标签里的内容
public static void asdf()
{
var strJson = @"1231231231231<a style=color:blue href=javascript:GetOrderDetails("1156605")>1156605<a>1231231231231233";
//方法一
Regex rg = new Regex(@"<a[^>]*>([^<]*)<a>");
MatchCollection mc = rg.Matches(strJson);
Console.WriteLine(mc[0].Groups[1].Value);
//方法二
var dd = Regex.Match(strJson, "<a[^>]*>([^<]*)<a>");
if (dd.Success)
Console.WriteLine(dd.Groups[1].Value);
//方法三
foreach (Match match in Regex.Matches(strJson, "<a[^>]*>([^<]*)<a>"))
Console.WriteLine("Duplicate "{0}" found at position {1}.", match.Groups[1].Value, match.Groups[2].Index);
}
运行结果
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。
- 上一篇: 编译windows版nginx-rtmp-module
- 下一篇: 使用p3p跨域设置Cookie
