Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regular Expressions

Status
Not open for further replies.

togatown

Technical User
Jun 23, 2003
65
0
0
US
I need to search through some HTML I've populated a variable with. I am looking to replace all of the content in between two comment tags. The content could vary.

In my HTML I have:

<!-- begin header row here -->
blah, blah, blah of varying content so I need a wildcard
<!-- end header row here -->

Thanks
 
Well, I thought it was the comment delimiters which were causing my problem but now I find through further testing that it is the whitespaces (newline, cr, tabs) which are doing it.

I need to match any and all characters between the two comments including special characters, line feeds, tabs, etc..

Any help appreciated.
 
Here I write example, maybe it helps:

<html>
<head>
<script language="javascript">
<!--
function replaceComment() {
var text = document.getElementById("ta1").value;
var res, pattern;
pattern = /(-->)([\s\S]*)(<!--)/mg;
res = text.replace(pattern, "$1\n"+"new text"+"\n$3");
alert(res);

}
//-->
</script>
</head>
<body>
<INPUT type="button" value="Test" onclick="return replaceComment()"> <TEXTAREA id="ta1">
</TEXTAREA>
</body>
</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top