Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/307.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/74.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#_Html_Regex - Fatal编程技术网

C# 获取组匹配的列表

C# 获取组匹配的列表,c#,html,regex,C#,Html,Regex,我有一个html示例 <a href="http://page.extension?querystrings" class="same-class">CONTENT1</a> <a href="http://page.extension?querystrings" class="same-class">CONTENT2</a> 为了获得所有内容,我尝试了一些不同的正则表达式匹配。 我在以下地点成功配对: 这只是第一场比赛。 但即使这样在C语言

我有一个html示例

<a href="http://page.extension?querystrings" class="same-class">CONTENT1</a>
<a href="http://page.extension?querystrings" class="same-class">CONTENT2</a>

为了获得所有内容,我尝试了一些不同的正则表达式匹配。 我在以下地点成功配对: 这只是第一场比赛。 但即使这样在C语言中也不起作用#

我有以下代码:

var matches = Regex.Matches(html, @"andOfQS"" class=""same-class"">(.*)<\/a>", RegexOptions.IgnoreCase & RegexOptions.Multiline);
    foreach (Match match in matches) {
    }
var matches=Regex.matches(html,@“andOfQS”“class=”“same class”“>(.*),RegexOptions.IgnoreCase&RegexOptions.Multiline);
foreach(匹配中的匹配){
}
但是,它返回0个匹配项。
请帮助我获取所有内容(1到n)。

您可以使用

谢谢您的机会。这是我的错。当我检查html时,它来自浏览器的源代码。当我运行代码时,它是来自WinForms Web浏览器的html。HTML完全不同。我找到了解决办法。

你可以试试
var matches = Regex.Matches(html, @"<a.*?class=""same-class"">(.*)<\/a>", RegexOptions.IgnoreCase & RegexOptions.Multiline);
    foreach (Match match in matches) {
    }