RegExp: Replacing with submatch

D

DrewM

I'm sure this isn't difficult, but it's Friday afternoon (!).

I'm trying to use a regular expression to match html tags in a string
and convert them to lower case. It's the RegExp object that I'm
struggling with rather then expression syntax.

So far I have this ('HELP!' denotes where I'm stuck):

private function recoverHTML(sHtml)
dim oRegExp
set oRegExp = new RegExp
oRegExp.IgnoreCase = False
oRegExp.Global = True
oRegExp.Pattern = "<(.*?)>"
sHtml = oRegExp.Replace(sHtml, HELP!)

set oRegExp = nothing
end function

I'm thinking of something like this:

"<" & lcase($1) & ">"

What syntax do I need here?

Thanks!

Drew
 
D

DrewM

DrewM said:
I'm thinking of something like this:
"<" & lcase($1) & ">"

Okay, I guess I should've just tried harder.

"<$1>" did the job. I also fixed my regexp to account for the closing slash.

oRegExp.Pattern = "<(/?.*?)>"
sHtml = oRegExp.Replace(sHtml, lcase("<$1>"))

However, it looks like the lcase() is applied before the submatch is
substituted, so it remains upper case.

Any ideas?

Drew
 
C

Chris Hohmann

DrewM said:
Okay, I guess I should've just tried harder.

"<$1>" did the job. I also fixed my regexp to account for the closing slash.

oRegExp.Pattern = "<(/?.*?)>"
sHtml = oRegExp.Replace(sHtml, lcase("<$1>"))

However, it looks like the lcase() is applied before the submatch is
substituted, so it remains upper case.

Any ideas?

<%
Dim s,re
s = "<StRoNg>Now</sTrOnG> is the <EM>hour</em> of our discontent..."
Set re = New RegExp
Function crf(m,p,s)
crf = LCase(m)
End Function
With re
..Global = True
..Pattern = "<[^>]+>"
Response.Write .Replace(s,GetRef("crf"))
End With
%>

http://msdn.microsoft.com/library/en-us/dnclinic/html/scripting121399.asp

HTH
-Chris Hohmann
 
D

DrewM

Chris said:
However, it looks like the lcase() is applied before the submatch is
substituted, so it remains upper case.
<%
Dim s,re
s = "<StRoNg>Now</sTrOnG> is the <EM>hour</em> of our discontent..."
Set re = New RegExp
Function crf(m,p,s)
crf = LCase(m)
End Function
With re
.Global = True
.Pattern = "<[^>]+>"
Response.Write .Replace(s,GetRef("crf"))
End With
%>

http://msdn.microsoft.com/library/en-us/dnclinic/html/scripting121399.asp

Wow, you learn something new :)
Thank you very much, Chris. That's a massive help.

Drew
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,740
Latest member
JudsonFrie

Latest Threads

Top