I would like to use regex to get the stylesheets inside it, I use this regex now: /(<link .*href=["'])/gi
but this returns me all <link but I want to filter on link and rel="stylesheet"
could someone help me out on this regex?
I would like to use regex to get the stylesheets inside it, I use this regex now: /(<link .*href=["'])/gi
but this returns me all <link but I want to filter on link and rel="stylesheet"
could someone help me out on this regex?
but this returns me all
Why not use the built-in querySelectorAll
var links = document.querySelectorAll("link[rel='stylesheet']");
console.log(links.length);
links is the list of link Elements.
Demo
var links = document.querySelectorAll("link[rel='stylesheet']");
console.log(links.length);
<link rel="stylesheet" href="abc.css"/>
<link rel="stylesheet" href="abc2.css"/>
If I have got you correctly then you are trying to get all links with rel="stylesheet" attribute. To do so you can use following regex
/<link .*rel="stylesheet".*\/>/gi
For demonstrations have a look here.