Regex只匹配计数1而不是2

本文关键字:Regex | 更新日期: 2023-09-27 18:17:07

这是我的正则表达式:

private static Regex _errorRegex = new Regex(" <div class='"styleRed'">(?<message>.*?)</div>", RegexOptions.IgnoreCase | RegexOptions.Singleline | RegexOptions.Compiled);

,网页的数据如下:

<div class="styleRed">• Zero is required in the Consideration Field for Deed Type CEDOT (Row 1). </div><div class="styleRed">• Zero is required in the Assume/Value Field for Deed Type CEDOT (Row 1). </div>

var matches = _errorRegex.Matches(webpage);

匹配计数总是1。你知道我错过了什么吗?

Regex只匹配计数1而不是2

您的正则表达式模式以空格开头。

在您的示例中,HTML页面上的第二个div前面没有空格。