How 'bout doing it in two steps: First flag all the text strings that you
want to apply the style to by surrounding them with some rarely encountered
chars...

REReplaceNoCase(threads.message, "(#query#)","~~\1~~","ALL");

then go through and apply the styles to all the strings...

REReplaceNoCase(threads.message, "~~([^~]*)~~","<SPAN
CLASS='highlight'>\1</SPAN>", "ALL");

Note: To insure that a ~ appearing in the text is handled correctly, just
replace all ~ with "some unique string !@$$%@" before doing the above, and
then replacing all occurrences of "some unique string !@$$%@" with ~ after
you're done.

Hope that helps.

Michael Robert Westcott
http://www.help-u-web.com
Webmaster Services
----- Original Message -----
From: Brent Goldman <[EMAIL PROTECTED]>
Newsgroups: cf-talk
Sent: Wednesday, October 25, 2000 5:40 PM
Subject: searching arrays with regular expressions


| Hello,
|
| I am having the search function of a CF template highlight words that a
user
| entered in their query.  For example, if someone searches for "test" in
the
| query box, it would then go through and replace the word "test" with a
span
| tag with class "highlight" in order to highlight it.  The following code
is
| how I did it:
|
| REReplaceNoCase(threads.message, "(#query#)","<SPAN
| CLASS='highlight'>1</SPAN>", "ALL");
|
| After implementing this feature, I made it so that the CF template takes
all
| the words in the string "query", and makes and array out of it called
| "keywords", with each element of the array being a different word from the
| original string "query."  To make it do that the search/highlighting
| function worked with the new code, I did a CFLOOP of the REReplaceNoCase
| function, each time making the word to change a different element in the
| keyword array.  The only problem was, if someone searched for something
with
| the words "span" or "highlight" or any part of those words, the second
time
| the loop went around it would replace the things it itself added into the
| message, thus making it so that the highlighting of the first word in the
| keywords array wouldn't work, and would even display partial HTML around
it.
| Is there a way to make the REReplaceNoCase function search through a
message
| and replace any word that appears in a certain array rather than replacing
a
| single word?
|
| Thanks,
| Brent
|
| --------------------------------------------------------------------------
----------------------
| Archives: http://www.mail-archive.com/[email protected]/
| Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists or send
a message with 'unsubscribe' in the body to
[EMAIL PROTECTED]

------------------------------------------------------------------------------------------------
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists or send a message 
with 'unsubscribe' in the body to [EMAIL PROTECTED]

Reply via email to