Search for a word and highlight in Red

Find, replace, find in files, replace in files, regular expressions

Search for a word and highlight in Red

Postby Isay2U » Fri Dec 02, 2005 12:29 am

This might be really simple.

How can I search for a word in a file and have the word highlighted in a color, like red.

Thanks for any help in advance.
Rgds
User avatar
Isay2U
Newbie
 
Posts: 7
Joined: Fri Oct 14, 2005 11:00 pm

Re: Search for a word and highlight in Red

Postby Mofi » Sat Feb 25, 2006 6:21 pm

I think you want to see all words found highligted in red in UltraEdit. Such a feature is not available in UltraEdit. What do you think about the List Lines Containing String option of the find dialog?

Or do you edit a HTML file and you want to highlight all words found by your search string highlighted in red if viewed with a WWW browser? This could be for example realized with following regular expression in UltraEdit style:

Find What: ^(your search string^)
Replace With: <span style="color:red">^1</span>


Note: I have a dirty trick to highlight all simple words or keyphrases found by a search string in UltraEdit by use of syntax highlighting. The technique used for this special highlighting is to not search for a word or phrase, but to run a Replace All and add marker characters at start and end of the found strings. But you have to run a second Replace All to remove the marker characters which are just added for highlighting the strings you searched (exactly replaced) for. Are you interested in what must be configured to use this dirty trick and how to use it?
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4064
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Search for a word and highlight in Red

Postby Isay2U » Mon Mar 06, 2006 11:49 am

Thank you, Mofi.

I am interesting in the syntax highlighting trick you mentioned.

Your replies are always good.

rgds
David
User avatar
Isay2U
Newbie
 
Posts: 7
Joined: Fri Oct 14, 2005 11:00 pm

Re: Search for a word and highlight in Red

Postby Mofi » Mon Mar 06, 2006 3:32 pm

Well, before I start I will inform you, that "search for a word in a file and have the word highlighted in a color" will be available in UltraEdit v12.00. It's already available in v12.00beta2 for the beta testers.

To highlight single-line phrases with the dirty trick you have to add into the wordfile for every language definition you use (/L1"C/C++", /L3"HTML", ...) the following line:

/Marker Characters = "»«"

You can use other characters, but these marker characters should not exist in your files anywhere.

You also have to define this pair of marker characters in an existing or better a new color group at every language where these marker characters are specified. For example:

/C8"Found strings"
»«

That's it. Now all strings in a line starting with » and ending with « will be highlighted with color 8. This method cannot be used for multi-line strings.

For multi-line strings the alternate block comment could be used instead of marker characters. Using alternate block comment has also an additional advantage: instead of a single character to mark the start and end of the search string you can use a real string (with up to 5 characters) for marking the string.

To get all found strings highlighted, you now have to run a replace instead of a find.

Find What: your search string
Replace With: »your search string«

But don't forget to UNDO this replace are run again a replace - a regular expression replace - to remove all »«.

Find What: [»«]
Replace With:

Replace with nothing!
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4064
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Search for a word and highlight in Red

Postby Isay2U » Mon Mar 06, 2006 11:55 pm

Thank you Mofi.

I am glad that this function in now included in v12.x.

Rgds
David
User avatar
Isay2U
Newbie
 
Posts: 7
Joined: Fri Oct 14, 2005 11:00 pm


Return to Find/Replace/Regular Expressions