ahosang
05-16-2003, 01:25 AM
Let's say i had a string of HTML(as a variable). But this string could contain newline(linefeed or carriage return) as HTML often does.
I want to match say the contents of any<script> tag and it contents - then replace with empty string.
<html>
<head>
<title></title>
<script>
function stripHtml(strHTML) {
var strOutput="";
scriptPattern=/<script>.*<\/script>/gi;
// Replace all script with an empty string
strOutput = strHTML.replace(scriptPattern, "");
alert(strOutput);
}
</script>
</head>
<body onload="stripHtml(document.body.innerHTML)">
Test Page<br>
<script>
var hello="world";
var second="good";
</script>
<b><u>test block of <i>text</i> to see the script</u></b>
</body>
</html>
Doesn't work as is because of the newLines. Works if you make the script tag and content one line - that's not the workaroud. I'm trying to make it work with linefeeds.
Say you involve the linefeeds:
scriptPattern=/<script>\r*\n*.*\n*\r*<\/script>/gi;// my other attempt
A script could contain a number of lines. I want the regExp to just match any pair of script tags and whatever could lie between (lots of characters and linefeeds possibly)
I want to match say the contents of any<script> tag and it contents - then replace with empty string.
<html>
<head>
<title></title>
<script>
function stripHtml(strHTML) {
var strOutput="";
scriptPattern=/<script>.*<\/script>/gi;
// Replace all script with an empty string
strOutput = strHTML.replace(scriptPattern, "");
alert(strOutput);
}
</script>
</head>
<body onload="stripHtml(document.body.innerHTML)">
Test Page<br>
<script>
var hello="world";
var second="good";
</script>
<b><u>test block of <i>text</i> to see the script</u></b>
</body>
</html>
Doesn't work as is because of the newLines. Works if you make the script tag and content one line - that's not the workaroud. I'm trying to make it work with linefeeds.
Say you involve the linefeeds:
scriptPattern=/<script>\r*\n*.*\n*\r*<\/script>/gi;// my other attempt
A script could contain a number of lines. I want the regExp to just match any pair of script tags and whatever could lie between (lots of characters and linefeeds possibly)