Quantcast
Channel: Apache OpenOffice Community Forum
Viewing all articles
Browse latest Browse all 1281

Writer • Re: [Solved] Replace expression with partial italics

$
0
0
I need to replace the string "abc" (no formatting) with the string "abc def" but I need the "def" bit – and only the "def" bit – in italics.
If abc is followed by a space you can do this in one step. In the following text ␢ represents a space.

Edit → Find & Replace → More options, select Regular Expressions, Search for (?<=abc)␢, Replace with ␢def␢ → Format → Typeface → Italic → OK, Replace All. I recommend unchecking Regular expressions, before clicking Close.

(?<=abc)␢ is a lookbehind assertion. It matches a space preceeded by abc, but only matches the space. The Replace All changes those spaces to space def space, all in italics, but you won't notice that those spaces are italicized.

It would be nice to use regular expression (?<=abc)(?=.*?). As before it looks for something after abc. (?=.*?) is a lookahead assertion. It finds, but does not match, a zero-length string after abc. Then we could replace the zero-length string between the assertions with space def space, italicized. However it seems that in the Find and Replace feature zero-length strings cannot be matched.

Statistics: Posted by MrProgrammer — Tue Nov 12, 2024 6:14 am



Viewing all articles
Browse latest Browse all 1281

Trending Articles