Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在C中定义正则表达式#_C#_Regex - Fatal编程技术网

C# 在C中定义正则表达式#

C# 在C中定义正则表达式#,c#,regex,C#,Regex,我想问,如何在C中定义正则表达式# 我有一个文本框,用户将在其中写下作者的名字,谁应该找到。 我想定义将在HTML内容中找到的正则表达式 <span class ="author">John</span> <span class ="song">Hooray</span> 约翰 好极了 类似于:用户将John放入文本框,程序检索他万岁 我的尝试: MatchCollection m1 = Regex.Matches(html, @"<sp

我想问,如何在C中定义正则表达式#

我有一个文本框,用户将在其中写下作者的名字,谁应该找到。 我想定义将在HTML内容中找到的正则表达式

<span class ="author">John</span>
<span class ="song">Hooray</span>
约翰 好极了 类似于:用户将John放入文本框,程序检索他万岁

我的尝试:

MatchCollection m1 = Regex.Matches(html, @"<span class=("[\w\d]*")\sauthor=("[\w\d]*")>([\w\d]*)</span>", RegexOptions.Singleline);
MatchCollection m1=Regex.Matches(html,@“([\w\d]*)”,RegexOptions.Singleline);

如评论中所述,在HTML上使用正则表达式没有任何好处。但是,如果(且仅当)标记像您的示例中那样简单,您可能会得到如下结果:

    @"<span class=""author"">(?<author>[^<]+)</span>" 

@(?[^您需要使用HTML解析器,并将用户键入的值作为XPath表达式的一部分传递到文本字段中。是的,解析器是正确的工具。在HTML上使用正则表达式几乎总是一个坏主意。不要使用正则表达式解析HTML。回答得好,我对问题的质量非常怀疑。显示出明显的缺少re搜索