Given a string of html like the one below:
<html>
<link rel="stylesheet" href="/thing.css">
<body>
<script src="/nothing.js"></script>
<link rel="stylesheet" href="/styles.css">
<a href='#a_hash'>A link</a>
</body>
</html>
I want to be able to get the following:
<html>
<link rel="stylesheet" href="//example.com/thing.css">
<body>
<script src="//example.com/nothing.js"></script>
<link rel="stylesheet" href="//example.com/styles.css">
<a href='//example.com#a_hash'>A link</a>
</body>
</html>
And I preferably need to do this without a library, and in vanilla JavaScript. Currently I have this regex to find urls (I'm open to new ones!):
<.+?(?:href|src)=(?:"|')([^"']+)(?:"|').*?>