• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

replace issue

New Here ,
Mar 25, 2009 Mar 25, 2009

Copy link to clipboard

Copied

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.
TOPICS
Advanced techniques

Views

278

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 25, 2009 Mar 25, 2009

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 01, 2009 Apr 01, 2009

Copy link to clipboard

Copied

LATEST
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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation