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

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

Last post 06-29-2008, 2:35 PM by ddrudik. 1 replies.
Sort Posts: Previous Next
  •  06-28-2008, 7:55 PM 43570

    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

  •  06-29-2008, 2:35 PM 43584 in reply to 43570

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

    This might be rather difficult with vbscript since you doesn't support lookbehind (let alone support variable-length lookbehind which is the common solution for this problem).  If vbscript supported something like PHP's preg_replace_callback to apply a function to the regex matches that would be another option (unfortunately it does not support anything similar).
View as RSS news feed in XML