regex to match specific html tags
- by Rco8786
I need to match html tags(the whole tag), based on the tag name.
For script tags I have this:
<script.+src=.+(\.js|\.axd).+(</script>|>)
It correctly matches both tags in the following html:
<script src="Scripts/JScript1.js" type="text/javascript" />
<script type="text/javascript" src="Scripts/JScript2.js" />
However, when I do link tags with the following:
<link.+href=.+(\.css).+(</link>|>)
It matches all of this at once(eg it returns one match containing both items):
<link href="Stylesheets/StyleSheet1.css" rel="Stylesheet" type="text/css" />
<link href="Stylesheets/StyleSheet2.css" rel="Stylesheet" type="text/css" />
What am I missing here? The regexes are essentially identical except for the text to match to?
Also, I know that regex is not a great tool for HTML parsing...I will probably end up using the HtmlAgilityPack in the end, but this is driving me nuts and I want an answer if only for my own mental health!