正则表达式在模拟器中工作,但在C#实现中失败。我错过了什么?

正则表达式在模拟器中工作,但在C#实现中失败。我错过了什么?,c#,regex,C#,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 { p

这是我编写的正则表达式,它在调试器工具中工作:

(<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);
        }
    }
}
使用系统;
使用System.Text.RegularExpressions;
公开课范例
{
公共静态void Main()
{
字符串模式=@“(

AAPG回忆录110

"; RegexOptions选项=RegexOptions.Multiline; foreach(在正则表达式中匹配m.Matches(输入、模式、选项)) { WriteLine(“{0}”位于索引{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";
String srcstr3=Web\u描述;

字符串匹配模式3=@”(多亏了@DragandDrop,我意识到Razor中的HTML与调试工具中的HTML不同。

请定义不起作用。它在c#fiddle上起作用。你期望什么?它有什么问题?甚至你的第二块代码也起作用:。你确定
srcstr3
包含与
var input
相同的字符串吗?请检查你的
>字符串srcstr3=Web\u Description;
,它包含什么?