By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,852 Members | 2,259 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,852 IT Pros & Developers. It's quick & easy.

Remove all javascript code/content/references from the HTML code using Perl code lang

P: 1
Hi Experts,

I have a simple Perl code, in this, I have a Perl variable , say

$original = '<html>........................................... ...............................<html>'

in between this <HTML> tag, let's say, I have a lots of JavaScript code along with the HTML code, say <script> ..... </script> and also have inline javascript references , say , <input type = "text" name = "ok" value = "2" onclick=onClick="javascript: function('value')" >.

I want to remove all the JavaScript related things, and just want HTML code/content/tag.

Can you please help me out?

Thanks
Shiv
Apr 7 '10 #1
Share this Question
Share on Google+
1 Reply


Expert 100+
P: 785
Just use a non-greedy Regular Expression to delete the javascript:
Replace "<script>.*?</script>" with empty string everywhere.
Keep care of the upper/lowercase characters by either transforming the string before replacement or by using "(?i)" in front of your Regular Expression.
Extend your Regular Expression to skip white spaces inside the tags and also characters that could follow inside the opening tag. For example "<script language=javascript color=red>" or "</script >"
Apr 8 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.