RegExp: Replacing with submatch

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • DrewM

    RegExp: Replacing with submatch

    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(sHt ml)
    dim oRegExp
    set oRegExp = new RegExp
    oRegExp.IgnoreC ase = 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

  • DrewM

    #2
    Re: RegExp: Replacing with submatch

    DrewM wrote:
    [color=blue]
    > I'm thinking of something like this:
    > "<" & lcase($1) & ">"[/color]

    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

    Comment

    • Chris Hohmann

      #3
      Re: RegExp: Replacing with submatch

      "DrewM" <bogus@doesntex ist.com> wrote in message
      news:eMUSPd0jDH A.2512@TK2MSFTN GP09.phx.gbl...[color=blue]
      > DrewM wrote:
      >[color=green]
      > > I'm thinking of something like this:
      > > "<" & lcase($1) & ">"[/color]
      >
      > Okay, I guess I should've just tried harder.
      >
      > "<$1>" did the job. I also fixed my regexp to account for the closing[/color]
      slash.[color=blue]
      >
      > 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?[/color]

      <%
      Dim s,re
      s = "<StRoNg>No w</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,GetR ef("crf"))
      End With
      %>

      Learn with interactive lessons and technical documentation, earn professional development hours and certifications, and connect with the community.


      HTH
      -Chris Hohmann


      Comment

      • DrewM

        #4
        Re: RegExp: Replacing with submatch

        Chris Hohmann wrote:
        [color=blue][color=green]
        >>However, it looks like the lcase() is applied before the submatch is
        >>substituted , so it remains upper case.[/color]
        > <%
        > Dim s,re
        > s = "<StRoNg>No w</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,GetR ef("crf"))
        > End With
        > %>
        >
        > http://msdn.microsoft.com/library/en...ting121399.asp[/color]

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

        Drew

        Comment

        Working...