想要提取数据的代码:
<div class="Content">
<div>
<h3>Opening hours:</h3>
<div>I want to get this text</div>
</div>
</div>
我尝试使用此代码:
Match OpeningHours = Regex.Match(data, "<h3>Opening hours:</h3>\n<div>(.+?)</div>");
if (OpeningHours.Success)
{
string nOpeningHours = OpeningHours.Groups[1].Value;
company.OpeningHours = nOpeningHours;
}
答案 0 :(得分:2)
您需要在\s*
之后使用\n
,以便</h3>\n
匹配后的空格或偶数换行符。 \s
匹配任何类型的垂直或水平空格字符。
Regex.Match(data, @"<h3>Opening hours:</h3>\n\s*<div>(.+?)</div>");