2 Replies Latest reply on Apr 1, 2009 12:26 AM by Sam_Ham

    replace issue

    Sam_Ham
      Hi,

      I've got a problem, which appears to be quite simple but I'm struggeling to find the solution.

      I'm doing a replace on specific strings in my content which is being pulled into my pages.

      e.g. <cfset request.vContent = Rereplace(request.vContent, "\bMyWord\b","\bMyNewWord\b", "ALL")>

      This words fine... infact it words too well as it also replaces the string "myWord" in anchor text and titles, which is what i need to eliminate.

      for example <a href="www.MyWord.com" title="MyWord">MyWord link</a>

      becomes: <a href="www.MyNewWord.com" title="MyNewWord">MyNewWord link</a>

      when it needs to be: <a href="www.MyWord.com" title="MyWord">MyNewWord link</a>

      Thanks in advance for any advice.

      Sam.
        • 1. Re: replace issue
          Level 7
          Sam_Ham wrote:
          > Hi,
          >
          > I've got a problem, which appears to be quite simple but I'm struggeling to
          > find the solution.

          For a solution that works 100% I think you'll need to parse the HTML
          into a DOM and replace the text only in the text nodes.

          A solution that works in 80-90% of the cases:
          <cfset request.vContent = Rereplace(request.vContent,,
          "([[:space:]<>])MyWord([[:space:]<>])","\1MyNewWord\2", "ALL")>

          --
          Mack
          • 2. Re: replace issue
            Sam_Ham Level 1
            Hi Mack,

            I tested the the Rereplace code and you're correct, it's not consistant enough for the job in hand.

            I'm not quite sure how you can parse the HTML into a DOM and replace the text only in the text nodes. If you could give me some advice on this it would be a great help.