I am trying to figure out how to write a regex that would provide the url from a string like this:
'<script type="text/javascript" src="http://chrismills.la/test.js"></script>';
This works, but I need to find a cleaner way to do this:
var url = '';
_content.replace(/src ?= ?"([^"]+)"/gi, function(res) {
url = res;
url = url.replace('src=','');
url = url.replace(/['"]+/g, '')
url = url.replace(/["']+/g, '')
});
script.src = url;
In action: http://jsfiddle.net/zb3jh180/
SOLUTION, based on answer below:
var regex = /<script.*?src="(.*?)"/gmi;
var url = regex.exec(_content);
script.src = url[1];