I have the following code to attempt to extract the content of li tags.
string blah = @"<ul>
<li>foo</li>
<li>bar</li>
<li>oof</li>
</ul>";
string liRegexString = @"(?:.)*?<li>(.*?)<\/li>(?:.?)*";
Regex liRegex = new Regex(liRegexString, RegexOptions.Multiline);
Match liMatches = liRegex.Match(blah);
if (liMatches.Success)
{
foreach (var group in liMatches.Groups)
{
Console.WriteLine(group);
}
}
Console.ReadLine();
The Regex started much simpler and without the multiline option, but I've been tweaking it to try to make it work.
I want results foo
, bar
and oof
but instead I get <li>foo</li>
and foo
.
On top of this I it seems to work fine in Regex101, https://regex101.com/r/jY6rnz/1
Any thoughts?