> This is the replace statement a regex guru gave me 
> to wrap a variable found in a string in a span tag. 

Not sure you can call them a "guru" when the only piece of regex used is a pair 
of parentheses which are entirely unnecessary. *shrug*

Here's a simpler version that does exactly the same thing:

        REReplaceNoCase
                ( answer
                , search_string
                , '<span class="keyword">\0</span>'
                , 'all'
                )

However, what that isn't doing is escaping potential regex metacharacters 
inside search_string (which could then result in unexpected behaviour).

If you can't guarantee there will not be any metacharacters present, you need 
to do this:

        REReplaceNoCase
                ( answer
                , search_string.replaceAll('[$^*()+\[\]{}.?\\|]','\\$0')
                , '<span class="keyword">\0</span>'
                , 'all'
                )

(Which prefixes the relevant characters with a backslash to escape them.)


Anyhow, as for your actual problem, regex is not a good tool for parsing HTML 
(which is what you're asking to be done by excluding tag attributes from 
matching).

What you need to do is use a HTML parsing library, such as jSoup, to isolate 
the text segments within HTML tags, and loop through performing your replace 
operation on each of those in turn (recursing down through any child tags as 
required).

Using jSoup, this can be achieved with the textNodes() method, to access the 
individual segments of text and child nodes:
http://jsoup.org/apidocs/org/jsoup/nodes/Element.html#textNodes()

If you're unfamiliar with using JARs in CF, Ben Nadel has a post on using jSoup 
with CF10:
http://www.bennadel.com/blog/2358-Parsing-Traversing-And-Mutating-HTML-With-ColdFusion-And-jSoup.htm
 


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:351784
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm

Reply via email to