...

View Full Version : Replace by tags?



angst
02-27-2006, 07:57 PM
Hello,
I'm wondering how I can do a replace on a chunk of html code using tags.

example, I want to replace the following tag and everything in between.
<!--start-->
HTML STUFF
<!--stop-->


how can this be done?

thanks in advance for your time!
-ken

Brandoe85
02-27-2006, 08:07 PM
I'd take a look at regular expressions, 4guys has an article on it:
http://www.4guysfromrolla.com/webtech/120400-1.shtml

Let us know if you run into any problems.

Good luck;

angst
02-27-2006, 08:20 PM
hmm, I've never used regular expressions before, though I know of them.

I ended up doing this:

TempStart = InStr(rsPoOutPut("PoHTML"),"<!--start-->")
TempStop = InStr(rsPoOutPut("PoHTML"),"<!--stop-->")

StrHTMLTempStart = left(rsPoOutPut("PoHTML"),TempStart)
StrHTMLTempStop = left(rsPoOutPut("PoHTML"),TempStop)
StrHTMLCut = replace(rsPoOutPut("PoHTML"),StrHTMLTempStop,"")
StrHTMLCut = StrHTMLTempStart&""&StrHTMLCut


do you think this is too messy of a solution? it's working, but seems a little hacked too me.

thanks again,
-Ken

Brandoe85
02-27-2006, 08:53 PM
Heres maybe one possiblity with a regex:


<%@ Language=VBScript %>
<html>
<head>
</head>
<body>
<%

Dim objReg
Dim strTest
Dim objMatches

strTest = "<!--start-->this is some html <!--stop--><br>this is text after tags"
Response.Write("The string before the regex <br><b>" & strTest & "</b>")
Set objReg = new RegExp
objReg.Pattern = "<!--start-->(.*?)<!--stop-->"
objReg.IgnoreCase = true
objReg.Global = true
Set objMatches = objReg.Execute(strTest)
Response.Write("<br><hr>The string after regex <br><b>" & Replace(strTest, objMatches(0).Value, "Replacement") & "</b>")

%>
</body>
</html>


Let me know how that goes.

Good luck;



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum