House of Fusion
Search over 2,500 ColdFusion resources here
  
Home of the ColdFusion Community

Mailing Lists
Home /  Groups /  ColdFusion Talk (CF-Talk)

Replace Question

  << Previous Post |  RSS |  Sort Oldest First |  Sort Latest First |  Subscribe to this Group Next >> 
Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Robert Harrison
06/27/2012 02:25 PM

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_

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Robert Harrison
06/27/2012 02:30 PM

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:   Better written results: #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_

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Eric Roberts
06/27/2012 06:57 PM

Is there something in your CSS that is changing it to lower case? Eric Roberts Owner/Developer Three Ravens Consulting owner@threeravensconsulting.com http://www.threeravensconsulting.com tel: 630-881-1515 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:   Better written results: #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_

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Michael Dinowitz
06/27/2012 02:42 PM

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 <robert@austin-williams.com ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Robert Harrison
06/27/2012 02:51 PM

> # REReplaceNoCase(answer, '(#search_string#)', '<span class="keyword">\1</span>', 'all')# Nice. Works perfectly. Thank You... just waiting for someone to complain about the nested ##'s though LOL :-) 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_

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Matt Quackenbush
06/27/2012 02:57 PM

Stop nesting #s!!  You're needlessly killing kittens!!! :D #reReplaceNoCase( answer, search_string, '<span class="keyword">\1</span>', 'all' )# ;-) On Wed, Jun 27, 2012 at 1:51 PM, Robert Harrison <robert@austin-williams.com ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Robert Harrison
06/27/2012 03:09 PM

> Stop nesting #s. You're needlessly killing kittens!!! I was sooo waiting for that shoe to drop :-) 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_

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Matt Quackenbush
06/27/2012 03:37 PM

I hope you noticed that I posted that _because_ you said you were waiting on it.  ;-) On Wed, Jun 27, 2012 at 2:08 PM, Robert Harrison <robert@austin-williams.com ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Robert Harrison
06/27/2012 04:02 PM

Got it. 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_williams I hope you noticed that I posted that _because_ you said you were waiting on it.   ;-) On Wed, Jun 27, 2012 at 2:08 PM, Robert Harrison <robert@austin-williams.com ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Michael Dinowitz
06/27/2012 03:02 PM

On Wed, Jun 27, 2012 at 2:51 PM, Robert Harrison <robert@austin-williams.com ----- Excess quoted text cut - see Original Post for more ----- '(' & search_string & ')' I drop all attempts at being anal about #s when I'm working with RegEx. RegEx is anal enough.

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Peter Boughton
07/02/2012 09:23 AM

>This is a case for Regular Expressions (RegEx): > >REReplaceNoCase(answer, '(#search_string#)', '<span >class="keyword">\1</span>', 'all')# > Heh, just seen this after the other thread, so guess I'll repeat what I said there: Using parentheses is completely unnecessary. Use \0 in the replacement string instead. If search_string is (for example) "$10" or ":)" or "a+b^c" or whatever then simply using it as a regex_pattern will cause problems. To solve this means escaping the meta-characters, for example, search_string.replaceAll('[$^*()+\[\]{}.?\\|]','\\$0') Putting both those together results in:   REReplaceNoCase     ( answer     , search_string.replaceAll('[$^*()+\[\]{}.?\\|]','\\$0')     , '<span class="keyword">\0</span>'     , 'all'     ) (Though of course, as noted in the other thread, this doesn't deal with HTML.)


<< Previous Thread Today's Threads Next Thread >>

Search cf-talk

May 23, 2013

<<   <   Today   >   >>
Su Mo Tu We Th Fr Sa
       1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31   

Designer, Developer and mobile workflow conference