Take CSS link with Regex

Asked

Viewed 108 times

1

Good morning guys, when pulling the html of the entire page in string it also brings some reference links:

<link href="~/Content/item/item.min.css" rel="stylesheet" />

I already removed the tags and , but I need to remove this and I’m not getting, the code I use to remove the script and style tags is this:

var regex = new Regex("(\\<script(.+?)\\</script\\>)|(\\<style(.+?)\\</style\\>)",
            RegexOptions.Singleline | RegexOptions.IgnoreCase);
        HTMLemString = regex.Replace(HTMLemString, "");

If anyone can help me I’d appreciate it.

  • What you want to leave?

  • All HTML but without these CSS links

  • 1

    Ttenta essa regex: <link[ >]*> ela da match com todas as tags <link/>

  • worked thanks :D

1 answer

0

As mentioned in the comments of the question, you can include the excerpt (<link[^>]*>) in its regular expression. This expression obtains all tags link, as examples may be:

<link rel="stylesheet" type="text/css" href="cg.css">
<link href="~/Content/item/item.min.css" rel="stylesheet" />

You can see/test this regex here.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.