这是我编写的Regex,可在调试器工具中使用:
(<a href="(http:\/\/store-assets.aapg.org\/documents\/previews\/\S+\/\S+\.pdf)".+<\/a>)
但是当我在Razor模板中尝试时,它无法获得匹配(Regex101.com生成的代码:
using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"(<a href=""(http:\/\/store-assets.aapg.org\/documents\/previews\/\S+\/\S+\.pdf)"".+<\/a>)";
string input = @"<div class=""dnnClear""><div itemprop=""description""> <b>This hardcover book contains extended abstracts of the articles. Full articles are on the included DVD.</b> <p></p>
<a href=""http://store-assets.aapg.org/documents/authors/M110pc1268AbouttheEditors.pdf"" target=""_blank"">About the Editors</a>
<p></p>
<a href=""http://store-assets.aapg.org/documents/toc/M110TOCpc1268.pdf"" target=""_blank"">Table of Contents</a></div> <div class=""store-item-desc dnnClear"">AAPG Memoir 110
<p></p>
<a href=""http://store-assets.aapg.org/documents/previews/1268M110/CHAPTER01.pdf"" target=""_blank"">View the first chapter</a></div></div>";
RegexOptions options = RegexOptions.Multiline;
foreach (Match m in Regex.Matches(input, pattern, options))
{
Console.WriteLine("'{0}' found at index {1}.", m.Value, m.Index);
}
}
}
我按如下所示将其调整为我的Razor模板-不起作用:
String srcstr3 = Web_Description;
String matchpattern3 = @"(<a href=""(http:\/\/store-assets.aapg.org\/documents\/previews\/\S+\/\S+\.pdf)"".+<\/a>)";
RegexOptions options3 = RegexOptions.IgnoreCase;
var pattern3 = new Regex(matchpattern3, options3);
Match match3 = pattern3.Match(srcstr3);
var chapter = (match3.Success) ? match3.Groups[2].Value : "did not match";
我想念什么?预先感谢您的帮助!
答案 0 :(得分:2)
由于@DragandDrop,我意识到Razor中的HTML与调试工具中的HTML不同。