As the title suggests I want to exclude the script tag.
Cause while using regex (at least I think that's the right name :P)
I get to a point where something
var wdc = /something/g;
is included inside the
var foundwdc = words.match(wdc).length;
So when I alert foundwdc it gives 3 "somethings" instead of the desired two inside the body
var words = document.getElementsByTagName('body')[0].innerHTML;
Hope this is clear enough :D and hope the title is right :P
Use replace()
to remove the script tag from string
var words = document.getElementsByTagName('body')[0].innerHTML.replace(/<script[^>]*>[\\s\\S]*?<\\/script>/gi, ''); console.log(words);
hi hello <script> </script>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.