×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Search Utilities

Highlighting Search Terms by Glowball
Posted: 14 Oct 01

If you search for "time" using a search utility, how do you highlight the word "time" throughout the results, without also highlighting "sometime" or "timeframe" or other variations?  The trick is to use Regular Expressions, or pattern matching.

This assumes someone submitted a form with a keyword to be searched.  These tags work on the results before they are displayed.

<cfset keyword = FORM.keyword>
<cfset oldResults = VARIABLES.results>
<cfset newResults = REReplaceNoCase(VARIABLES.oldResults, "(([^A-Za-z])(#Trim(VARIABLES.keyword)#)([^A-Za-z]))", "\2<b  style='background=color:yellow'>\3</b>\4", "ALL")>
<cfif Left(VARIABLES.newResults, Len(Trim(VARIABLES.keyword))) IS Trim(VARIABLES.keyword)>
    <cfset newResults = REReplaceNoCase(VARIABLES.newResults, "((#Trim(VARIABLES.keyword)#)([^A-Za-z]))", "<b style='background-color:yellow'>\2</b>\3", "ONE")>
</cfif>

What does the \2 \3 and \4 mean?  These are numbers to references pieces of the input to a regular expression function like REReplaceNoCase().  For example, see the following:

(\1 (\2)  (\3) (\4 (\5) ) )

Look at the placement of parentheses and numbers, \1 starts at the outermost pair of parentheses, and working your way in increases every number.  If they are on the same level of the hierarchy of parentheses, it goes from left to right in the expression.

Back to Adobe FAQ Index
Back to Adobe Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close