I need to get all script tags from an html string, separated the inline scripts and the "linked" scripts. By inline scripts I mean script tags without the src
attribute.
Here is how I get the "linked scripts":
<script(.)+src=(.)+(/>|</script>)
so, having <script
followed by one or more any character, followed by src=
, followed by />
or </script>
.
This works as expected.
Now I want to get all the script tags without the src tag, having some javascript code between <script .....>
and </script>
, but I can't figure it out how to do that. I just started understanding regular expressions, so the help of a more experienced r.e. guru is needed :)
UPDATE Ok, so dear downvoters. I have the html code for a whole html page in a variable. I want to extract script tags from it. How to do it, using jquery for example?
var dom = $(html);
console.log(html.find('script');
will not work. So, what is the way to accomplish that?
UPDATE 2 I don't need to solve this problem with regex, but because now I am learning about them, I thought I will try it. I am opened for any other solution.