[Solved] Using reg expressions to change font

Discuss the word processor
Post Reply
Straitsfan
Posts: 22
Joined: Mon Sep 29, 2008 11:31 pm

[Solved] Using reg expressions to change font

Post by Straitsfan »

Is there any way to use regular expressions to change the font (the color, for example) of the named pattern? I tired it on OO/LO but there doesn't seem to be a way to do it.

I tried it just no in both LO and OO, but can't figure out a way to do it. If I choose to change the font to the color red, for example, nothing happens. Is there a way to put in the replace box the pattern with the new color?
Last edited by Hagar Delest on Wed Dec 13, 2017 11:19 pm, edited 1 time in total.
Reason: tagged [Solved].
LO 5.2.3.3, OS X El Capitan
User avatar
Zizi64
Volunteer
Posts: 11358
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: using reg expressions to change font

Post by Zizi64 »

Please upload an ODF type sample file here.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
erbsenzahl
Volunteer
Posts: 255
Joined: Tue Apr 18, 2017 8:23 am
Location: Germany

Re: using reg expressions to change font

Post by erbsenzahl »

In general you don't need RegEx for that, only to select specific characters... See attachment:
FindAndReplaceFonts.png
You only have to Find All, then apply another font.

You can (!) additionally use RegEx as well (Search for: .*); I couldn't find any difference.

Please notice: There is also the option to find a style. If your text is defined by Character Styles so select that option - without that you can't find these characters...
LibreOffice current versions 7 and OpenOffice 4.1.15
on LinuxMint 20 - 21 Mate, W10-64 pro
Straitsfan
Posts: 22
Joined: Mon Sep 29, 2008 11:31 pm

Re: Using reg expressions to change font

Post by Straitsfan »

No, I need regular expressions, because the pattern is the same but it has different characters, a time stamp. I'm using the mac versions if that makes any difference. What do you mean by character styles? I'm unfamiliar with that.
LO 5.2.3.3, OS X El Capitan
User avatar
robleyd
Moderator
Posts: 5080
Joined: Mon Aug 19, 2013 3:47 am
Location: Murbko, Australia

Re: Using reg expressions to change font

Post by robleyd »

Have a look in the offline help - F1 - in the Writer section for character styles.
Cheers
David
OS - Slackware 15 64 bit
Apache OpenOffice 4.1.15
LibreOffice 24.2.2.2; SlackBuild for 24.2.2 by Eric Hameleers
Straitsfan
Posts: 22
Joined: Mon Sep 29, 2008 11:31 pm

Re: Using reg expressions to change font

Post by Straitsfan »

either way it doesn't work -- when I use it in Word version as well, it won't change the color of the search for pattern.
LO 5.2.3.3, OS X El Capitan
erbsenzahl
Volunteer
Posts: 255
Joined: Tue Apr 18, 2017 8:23 am
Location: Germany

Re: using reg expressions to change font

Post by erbsenzahl »

Straitsfan wrote:either way it doesn't work
More details!
Zizi64 wrote:Please upload an ODF type sample file here.
LibreOffice current versions 7 and OpenOffice 4.1.15
on LinuxMint 20 - 21 Mate, W10-64 pro
John_Ha
Volunteer
Posts: 9584
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Using reg expressions to change font

Post by John_Ha »

See [Tutorial] How to record a macro (and Regular Expressions) for help and links to documentation.

If your problem is solved please view your first post in this thread and click the Edit button (top right in the post) and add [Solved] in front of the subject.
LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
Straitsfan
Posts: 22
Joined: Mon Sep 29, 2008 11:31 pm

Re: Using reg expressions to change font

Post by Straitsfan »

Maybe I'm not being clear -- I know how to use regular expressions. The problem is that I simply want to change the color of whatever I've found. If I go into "Replace" and leave it blank, but change the color using the "Fonts" button it doesn't change the color of whatever has been found -- it deletes whatever has been found in the "Find" section of the dialog box. I don't have this problem when I use word.

Can anyone tell me how to simply change the color of text using "Find and Replace"? Is there any way to do it in AOO? Because if there is I don't know how.
LO 5.2.3.3, OS X El Capitan
User avatar
acknak
Moderator
Posts: 22756
Joined: Mon Oct 08, 2007 1:25 am
Location: USA:NJ:E3

Re: Using reg expressions to change font

Post by acknak »

For this kind of task, Find & Replace is not used to make changes to the formatting. Find & Replace is used only to *select* all the characters you want to re-color ("Find All"), then change the color in the usual way(s). The F&R dialog window is not "modal"; you can leave it open and still have access to all the usual formatting controls.
AOO4/LO5 • Linux • Fedora 23
Straitsfan
Posts: 22
Joined: Mon Sep 29, 2008 11:31 pm

Re: Using reg expressions to change font

Post by Straitsfan »

So if i understand you correctly, I have to manually change the color for each instance found, yes? If that's the case, then they need to update this, because I can do exactly that in Word.

Or, is it possible to use F&R to copy what has been found into the "Replace" section in addition to changing the color of the text?
LO 5.2.3.3, OS X El Capitan
User avatar
acknak
Moderator
Posts: 22756
Joined: Mon Oct 08, 2007 1:25 am
Location: USA:NJ:E3

Re: Using reg expressions to change font

Post by acknak »

Sorry I wasn't clear. Clicking "Find All" will select every match in the document. When you then change the color by clicking the toolbar or applying a style, every matching span of characters will be changed, just as when you select text manually and then apply some formatting. (You can also make multiple selections manually.)

Just to make this concrete, here is a complete step-by-step example:

1) File > New > Text Document

2) Type: dt
Press F3. This inserts a paragraph of "dummy text".

3) Edit > Find & Replace
Search for: \ba\S+
Replace with: empty
Options/Match case: ON
Options/Regular expressions: ON

Click Find All

You should now have every word beginning with 'a' selected (26 of them).

4) On the toolbar, click the "Font Color" pop-up and select a color. All of the selcted words should change font color.
AOO4/LO5 • Linux • Fedora 23
Straitsfan
Posts: 22
Joined: Mon Sep 29, 2008 11:31 pm

Re: Using reg expressions to change font

Post by Straitsfan »

That'll do it. Thanks.

Just curious -- what does the S mean in your pattern? It's not part of the expressions list.
LO 5.2.3.3, OS X El Capitan
erbsenzahl
Volunteer
Posts: 255
Joined: Tue Apr 18, 2017 8:23 am
Location: Germany

Re: Using reg expressions to change font

Post by erbsenzahl »

Straitsfan wrote:what does the S mean in your pattern?
https://en.wikipedia.org/wiki/Regular_expression wrote:\S Matches anything BUT a whitespace.
LibreOffice current versions 7 and OpenOffice 4.1.15
on LinuxMint 20 - 21 Mate, W10-64 pro
Straitsfan
Posts: 22
Joined: Mon Sep 29, 2008 11:31 pm

Re: Using reg expressions to change font

Post by Straitsfan »

Just curious again -- how did you know that? It's not in the list. I would have never known that.
LO 5.2.3.3, OS X El Capitan
User avatar
acknak
Moderator
Posts: 22756
Joined: Mon Oct 08, 2007 1:25 am
Location: USA:NJ:E3

Re: Using reg expressions to change font

Post by acknak »

Newer versions OO (and LibO) support "PCRE" regular expressions. If you Google that you'll get plenty of documentation for the details. The built-in documentation hasn't been updated, I suppose because there are already lots of other sources. The docs could at least point users to look at an outside source, I guess.
 Edit: PS: 
The documentation for the regex implementation used by OO/LO is here:
http://userguide.icu-project.org/string ... characters
AOO4/LO5 • Linux • Fedora 23
erbsenzahl
Volunteer
Posts: 255
Joined: Tue Apr 18, 2017 8:23 am
Location: Germany

Re: Using reg expressions to change font

Post by erbsenzahl »

LibreOffice current versions 7 and OpenOffice 4.1.15
on LinuxMint 20 - 21 Mate, W10-64 pro
Post Reply