View Full Version : Replace by tags?

02-27-2006, 06:57 PM
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.

how can this be done?

thanks in advance for your time!

02-27-2006, 07:07 PM
I'd take a look at regular expressions, 4guys has an article on it:

Let us know if you run into any problems.

Good luck;

02-27-2006, 07: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,

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

<%@ Language=VBScript %>

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>")


Let me know how that goes.

Good luck;