C# regex to find html tag
SPONSORED LINKS
Hi all,
I’m trying to analyze the data off some html files.
I want to retrieve the <meta name="keywords" content="keyword1, another_keyword" /> tag from the html. Using Regex I’m able to this via
Code:
MatchCollection keywords = Regex.Matches(html, "<meta name="keywords" content=".*" />");This works. Probably not the best regular expression written in history but it works. But now I noticed that on some pages the attributes in the tag have a different order, thus it changes to <meta content="keyword1, another_keyword" name="keywords" />. Now my Regex doesn’t work anymore.
I could solve it as following
Code:
MatchCollection keywords = Regex.Matches(html, "<meta name="keywords" content=".*" />");
if (keywords.Count == 0)
keywords = Regex.Matches(html, "<meta content=".*" name="keywords" />");But my guess is that there should be a way to this in one statement.
Original post:
C# regex to find html tag