Ask Your Question

is it possible to search for text of a specific color? [closed]

asked 2013-12-23 20:31:34 +0200

Sunny gravatar image

updated 2020-08-16 12:48:47 +0200

Alex Kemp gravatar image

I have an RTF document that has sections of red, blue, and even pink text. I want to put this document on an e-reader, but it is e-ink, and as such black-and-white.

I need to know if there's a way to search and replace the colored text with, say, underlines of different types, so I can still follow the text as it is meant to be.


edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Alex Kemp
close date 2015-11-16 18:33:18.008877

2 Answers

Sort by » oldest newest most voted

answered 2013-12-23 23:42:07 +0200

David gravatar image

updated 2013-12-27 21:31:35 +0200

[UPDATED] Yes, this is possible, but the approach used depends on the origins of the RTF file, since difference software will leave you with different markup (so it seems). Sunny's document is best treated with #2, below, "CTRL-H and Regex". Obviously, all testing should be done in a copy of the file, so you have your original, coloured version still available!

1. Using AltSearch extension

You need to download and install the very useful Alternative dialog Find & Replace (AltSearch) extension for Writer and install it. You'll get this garish green icon on your toolbar, but it's worth it: AltSearch icon

Then follow these steps:

(1) Position your cursor within the colour block you want to modify.
(2) Click the "AltSearch" icon, and select the "Properties" drop down, then the last option listed: "Same format of characters (based on cursor)". It should look like this:

AltSearch dialog

(3) When you click on that option, you'll see the "search" field populated as shown in the screen shot: that's the color of your text at cursor. Now click the Find All button (hidden in the screen shot), then Close the AltSearch dialog. All text in that colour is now "selected".
(4) Now use the Format > Character... > Font Effects > [Underlining] to choose your underlining of choice for this colour. Click OK.
(5) Repeat process for each colour.

When you're finished, use CTRL-A to select ALL, and set the Font Colour to "Automatic" from the drop-down on the toolbar.

That's you done. You should end up with all your text in black, but with the various bits of text that were originally colours now in various styles of underlining.

2. CTRL-H and Regex

You can also use the "native" search-replace function. First, use CTRL-H to bring up the "Find & Replace" dialog. Click the "Other Options" drop-down, if it isn't already open, and check the "Regular expressions" box:


(1) In the "Search for" field, put .* (that is, "dot" followed immediately by "asterisk"). Then click on the Format... button, and choose the "Font Effects" tab. Select the colour desired (Sunny's document uses "Light red", "Light blue", and "Light magenta").

(2) In the "Replace with" field, put & (ampersand) which means = "the text found in my search". Again choose the Format... button, but now choose "Automatic" for the font colour, and choose the "Underlining" style of choice for this colour.

(3) Hit Replace All, and you should have the coloured text chosen replaced with black text and its distinctive underlining.

(4) Repeat for each colour needing to be changed.

~ ~ ~ ~ ~ ~ ~ ~ ~ ~

It's not as tricky as it might sound, and once you've done it a couple times, will go very quickly, I think. This works for me with LibO Writer, and I'm on Linux Mint 13 LTS (Xfce) at the moment. Hope that helps!

edit flag offensive delete link more

answered 2013-12-24 06:05:58 +0200

Sunny gravatar image

updated 2013-12-24 09:05:31 +0200

I got to Step 2 before I had a failure.

I selected the text and brought up the AltSearch dialog. However, when selecting the option shown, I received the following error... (Turns out I can't post images. Sorry.)

Error Message: LibreOffice BASIC runtime error. Incorrect property value.

This also pulls up the macro code where the error is caused.

Macro code showing error line

It appears to be looking for a format name, not the existing formatting at that point. Since it's RTF, I'm not sure format names apply.

Since you seem to be able to perform this function, would it be possible for me to send the file to you and have you make the changes? Unless you can find a way around my error, I'm not sure there's much else I can do.

edit flag offensive delete link more


@Sunny - Hmmm... I can replicate this. Sorry. Let's do a little more investigating before I update my answer. Can you attach the file to your answer now? Or put it on dropbox or something and share the link? I'm pretty confident we can sort this, but it would help to have precisely the file you're working with, if you're willing.

David gravatar imageDavid ( 2013-12-24 11:37:19 +0200 )edit

Could it be that the RTF format’s properties can’t be handled by the extension’s code? @Sunny you could try to save the document as an ODT before attempting the replacements. What formats does the e-reader accept? LibO allows you to save the modified ODT back to RTF after the modifications are made. We’d only need to know if LibO’s RTF plays well with your e-reader model.

CyanCG gravatar imageCyanCG ( 2013-12-24 18:23:06 +0200 )edit

@CyanCG - I had attempted what you suggest in my experiements, and got different results depending on the origins of the RTF file. I've discovered more than one way to search on colour, but the results differ starkly depending on the underlying code -- I assume. Which has to do with the document's origins, I expect.

David gravatar imageDavid ( 2013-12-24 20:54:44 +0200 )edit

@David (et al) - For anyone who wishes, here's the link to a folder with both RTF and DOC versions of the file. Convert to your hearts' content, but let me know how it goes.

I hope that works.

Sunny gravatar imageSunny ( 2013-12-27 14:07:24 +0200 )edit

@Sunny - it did work (interesting document!), and results added to my "Answer", above. Use option #2, and you should be fine. (I live in hope!) I tested on the RTF, by the way, not the DOC.

David gravatar imageDavid ( 2013-12-27 21:33:28 +0200 )edit

@David - That has done the trick! Thanks so much for the insight and assistance. I am indebted to you for your help. I will be taking the link to the files down soon, just in case anyone else wants a peek at the document or wants to try they're hand at this technique. Probably the end of the week.

Sunny gravatar imageSunny ( 2013-12-30 08:34:14 +0200 )edit

@Sunny - hurrah! Glad it worked. Good question, and I learned something too! Could you mark that answer as "correct" (click the little check-mark symbol at the top of the Answer) so the issue is recorded as resolved? Thanks!

David gravatar imageDavid ( 2013-12-30 11:46:15 +0200 )edit

@David - Done, and link is now stale, documents removed.

Sunny gravatar imageSunny ( 2014-01-03 19:36:26 +0200 )edit

Question Tools

1 follower


Asked: 2013-12-23 20:31:34 +0200

Seen: 3,747 times

Last updated: Dec 27 '13