Got more questions? Find advice on: ASP | SQL | XML | Windows
Welcome to RegexAdvice Sign in | Join | Help

VBScript RexExp Replace a textstring only if not within tags <></>, possible?

  •  06-28-2008, 7:55 PM

    VBScript RexExp Replace a textstring only if not within tags <></>, possible?

    Hi, i got a dillema... for a company i need to make every occurence of it's company name to be in red and bold font.
    i have writen a simple function that i can call and filter all text database records

    Function companyName(inputText)
     If inputText<>"" Then
      companyName= Replace(inputText,"CompanyName","<font color=""#FF0000""><b>CompanyName</b></font>")
     Else
      inputText = ""
     End if
    End Function 

    Ok that above seems to work most of the time, only recently i have encountered a few glitches using the function as it is, i'll try to explain.

    If the "CompanyName" is found in a link, say <a href="http://www.companyname.com/someurl.htm">Some url</a> the link gets broken as the above function will replace the company name in the href invalid, same will occur in img tag making the img url invalid.
    mmn, now i'm thinking about it i believe only those 2 actually can break stuff, all other tags should be able to be replaced without wrecking the site

    Would there be a possibility using RegExp to replace only those strings when not in <a> and <img> tag?

    Please be gentle, these are my first steps into RegExp Wink

View Complete Thread