This is a case for Regular Expressions (RegEx):

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

1. Search the content of the variable answer
2. Look for the content of the variable search_string
2a. Because parenthesis are being used and we're doing RegEx, the matched
text will be 'captured' for later use. The parenthesis are special
characters, not part of what is being matched.
3. Replace the matched content with: <span class="keyword">\1</span>
3a. take the captured text from the match and place it within the span
block in place of the \1

\1 will contain the exact text matched with whatever case it had rather
than the case of the search_string


On Wed, Jun 27, 2012 at 2:25 PM, Robert Harrison <rob...@austin-williams.com
> wrote:

>
> I have a search results pages and I'd like to highlight the search term to
> show the matches. Of course, search is not case sensitive.
>
> On the results I can do something like:
>
>        ReplaceNoCase(answer, search_string,"<span
> class=""keyword"">#search_string#</span>","all")#
>
> This puts a nice little highlight around the search term and makes it easy
> to see in the results, but it may change the case.  For example, if I
> search for "mick jagger" and it finds "Mick Jagger", my answer come out
> like:
>
>        ... and a "mick jagger" was guy with big lips who dreamed of being
> a Beatle...
>
> Is there a way I could do the replace to highlight the result and NOT
> change the case?
>
> Thanks,
> Robert
>
> Robert Harrison
> Director of Interactive Services
>
> Austin & Williams
> Advertising I Branding I Digital I Direct
> 125 Kennedy Drive,  Suite 100   I  Hauppauge, NY 11788
> T 631.231.6600 X 119   F 631.434.7022
> http://www.austin-williams.com
>
> Blog:      http://www.austin-williams.com/blog
> Twitter:  http://www.twitter.com/austin_
>
> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
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:351740
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm

Reply via email to