【问题标题】:C# trying to isolate name from html using regexC# 尝试使用正则表达式从 html 中隔离名称
【发布时间】:2015-11-07 02:32:16
【问题描述】:
<a href="||blablabla link||" title="||blablabla title of torrent|| torrent">||THE STRING THAT IM INTERESTED IN--NAMES||</a>

我正在处理一个包含 20-30 条上述格式行的 html 文件!我有兴趣将所有名称保存在数组列表中。我的问题是我不太了解正则表达式格式来获取每个名称 我应该使用什么模式?我如何使用此模式来捕获此 html 字符串中的每个名称? 谢谢!

【问题讨论】:

  • 你需要显示更多格式,因为blablabla没用,html文件中有没有其他dom a

标签: c# html regex title


【解决方案1】:
string html = @"<a href=""/torrent/4353486/Terminator+Genisys+2015+720p+WEBRip+%5BChattChitto+RG%5D.‌​html"" title=""view Terminator Genisys 2015 720p WEBRip [ChattChitto RG] torrent"">Terminator Genisys 2015 720p WEBRip [ChattChitto RG]</a>";
string patten = @"<a\s+href=""[^""]*""\s+title=""[^""]*torrent"".*?>([^<]*)</a>";
foreach (Match m in Regex.Matches(html, patten, RegexOptions.IgnoreCase))
{
    Console.WriteLine(m.Groups[1].Value);
}

这是一个例子,我猜你的 dom 的标题必须以 torrent 结尾

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-14
    • 1970-01-01
    • 1970-01-01
    • 2010-10-25
    • 2016-01-22
    相关资源
    最近更新 更多