const regex = /<\s*?script\s*?([^>]*)\s*?>\s*?(.+)?\s*?<\s*?\/script\s*?>/gs;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('<\\s*?script\\s*?([^>]*)\\s*?>\\s*?(.+)?\\s*?<\\s*?\\\/script\\s*?>', 'gs')
const str = `< script type="text/javascript" src="//vk.com/js/api/openapi.js?65"> < /script >
<script type="text/javascript" >
VK.init({apiId: 3251711, onlyWidgets: true});
</script>
<script type="text/javascript" src="http://keddr.com/wp-content/themes/keddr3-1/js/lite-youtube.js" ></script>
<script type="text/javascript" src="http://keddr.com/wp-content/themes/keddr3-1/js/jquery.complexify.js" > sfdbb </script>
<script type="text/javascript" >
\$(function () {
if ((\$("#pass1").length 0)) {
\$("#pass1").complexify({}, function (valid, complexity) {
if (complexity < 1) {
\$('#progress').css({'width': complexity + '%'}).removeClass('progressbarValidGood').addClass('progressbarInvalid');
\$('.passAlert').hide();
} else if (complexity > 1 && complexity < 40) {
\$('#progress').css({'width': complexity + '%'}).removeClass('progressbarValidGood').addClass('progressbarInvalid');
\$('.passAlert.good').hide();
\$('.passAlert.bad').fadeIn();
} else if (complexity > 40) {
\$('#progress').css({'width': complexity + '%'}).removeClass('progressbarValidGood').addClass('progressbarValid');
\$('.passAlert.good').hide();
\$('.passAlert.strong').fadeIn();
}
\$('#complexity').html(Math.round(complexity) + '%');
});
}
});
</script >`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions