It's hard to put everything in the question's title since it's specific depends on what string people want to split. But here it is:
I have a string in which there are multiple script tags:
<script type="text/javascript" src="/javascripts/something-1.js"></script>
<script type="text/javascript" src="/javascripts/something-2.js"/>
<script type="text/javascript" src="/javascripts/something-3.js"></script>
<link rel="stylesheet" type="text/css" href="/something-1.css">
I want to split this string into multiple string, each contains a script tag (ignore link tags). This is how I did it:
var scripts = code.match(/<script.*src=.*(\/>|<\/script>)/g);
This is to match script tags with closing tag either />
or </script>
. However, with this current regex, I always get:
<script type="text/javascript" src="/javascripts/something-1.js"></script>
<script type="text/javascript" src="/javascripts/something-2.js"/>
as a string - not two.
How do I regex something like:
/<script.*src=( (not script not link) /> | (not link) <\/script> )/g