[Solved] How-search and bracket every italized word

Discuss the word processor
Post Reply
PeaceByJesus
Posts: 88
Joined: Mon Dec 24, 2007 7:38 pm

[Solved] How-search and bracket every italized word

Post by PeaceByJesus »

Hi, i much appreciated OOo, and am using 3.1.1. I would like to search search and replace to find every instance of italicized word in a large document, and then place brackets around it. I can find a specific italicized word by using the formatting option, but i just want to automatically find everyone, by using a wildcard perhaps. Any suggestions? Thanks
Last edited by TheGurkha on Tue Oct 13, 2009 11:53 pm, edited 1 time in total.
Reason: Tagged Solved.
Windows 11 Pro, Ryzen 3 3200G CPU; 64GB RAM
Grace and peace thru Jesus the Lord. peacebyjesus.net (pages created in Open office)
User avatar
RGB
Posts: 1456
Joined: Mon Oct 08, 2007 1:34 am

Re: How-search and bracket every italized word

Post by RGB »

Within the search menu, select "More options" and check "Regular expressions" (regular expressions are a "generalization" of wildcards). On "Search" write
(.*)
and select the Italics attribute as before. On "Replace with" write:
[$1]
Now click "Replace all".
There are two types of people: those who believe that there are two types of people and those who do not.

openSUSE Leap with KDE Plasma / LibreOffice
PeaceByJesus
Posts: 88
Joined: Mon Dec 24, 2007 7:38 pm

Re: How-search and bracket every italized word

Post by PeaceByJesus »

Well, may God bless you! :D I am amazed how some people know these things. One small adjustment though is that it places a space [is ] after the last letter, and also removes the space between the next word ([is ]no). I can fix the latter by placing a space after the [$1] , but the other space remains. BTW, is there a way to restrict the italicized characters to letters, excluding words? Almost there.
Windows 11 Pro, Ryzen 3 3200G CPU; 64GB RAM
Grace and peace thru Jesus the Lord. peacebyjesus.net (pages created in Open office)
tn@BeWo
Volunteer
Posts: 253
Joined: Fri Jul 24, 2009 8:26 am

Re: How-search and bracket every italized word

Post by tn@BeWo »

Obviously these spaces are italicized, too.
You can either search all white space and remove the format before your search,
or search for [:alpha:]* or [:alnum:]* instead of .*
or search for word boundaries, e.g. \<.*\>
or with non/capturing groups and more explicite back referencing for the replacement.
But I wouldn't recommend the latter to regex noobs, as long as you can do it without.
OOo 3.2.1 on ubuntu 10.4, MsWXP, MsW2k
PeaceByJesus
Posts: 88
Joined: Mon Dec 24, 2007 7:38 pm

Re: How-search and bracket every italized word

Post by PeaceByJesus »

Well, searching for [:alnum:]* (regular expressions, with format>italics) and replacing italicized words [$1] results in every italicized words or numbers being replaced with just, [] - w/out the word in it. Searching \<.*\> with [$1] ignores spaces but replaces words and numbers with []. Searching [:alpha:]*with [$1] does ignore the numbers but still replaces the italicized words with just []. I found you also have to be careful not to have spaces before or after the search term.

My work around is to search (.*), and replace with [$1], and then search for ] (with a space before it) and replace it with ] (no space). The numbers i can also deal with. As for regex noobs, that probably fits me, whatever it means. ;)
Windows 11 Pro, Ryzen 3 3200G CPU; 64GB RAM
Grace and peace thru Jesus the Lord. peacebyjesus.net (pages created in Open office)
User avatar
acknak
Moderator
Posts: 22756
Joined: Mon Oct 08, 2007 1:25 am
Location: USA:NJ:E3

Re: How-search and bracket every italized word

Post by acknak »

Well, searching for [:alnum:]* ... and replacing italicized words [$1] results in every italicized words or numbers being replaced with just, []
The parentheses are important: they direct Writer to save whatever matches between them so it can be recalled by "$1" in the replacement.

Try Search for: ([:alnum:]*)
AOO4/LO5 • Linux • Fedora 23
PeaceByJesus
Posts: 88
Joined: Mon Dec 24, 2007 7:38 pm

Re: How-search and bracket every italized word

Post by PeaceByJesus »

I see! I thought i had tried that, but search ([:alpha:]*) and replace with [$1] changes all the italicized words perfectly! Using ([:alnum:]*) does numbers also. Last question: any way to change two italicized words together (it is) ? As of now it places both in individual brackets. Thanks.
Windows 11 Pro, Ryzen 3 3200G CPU; 64GB RAM
Grace and peace thru Jesus the Lord. peacebyjesus.net (pages created in Open office)
tn@BeWo
Volunteer
Posts: 253
Joined: Fri Jul 24, 2009 8:26 am

Re: How-search and bracket every italized word

Post by tn@BeWo »

PeaceByJesus wrote:... [:alnum:]* ... results in ... being replaced with just, []
Oh well, I should've been more explicite.
tn@BeWo wrote:... [:alpha:]* or [:alnum:]* instead of .*
referred to
RGB wrote:... (.*)
and was meant to replace the content of the brackets rather than the whole group - sorry for the inconvenience.

As for spaces (single spaces? arbitrary number of occurrencies - i.e. n words/expressions with n-1 spaces between them?), you might try
([^ ]+([ ]?[^ ]+)+)
[$1]
Different from the POSIX classes, this will also match words containing ' like in "We'll see", - like in "dead-end" and other in-italics-punctuation.
It will break up groups seperated by 2 or more spaces.
If it's still not what you need, it should give you a good start for further testing.
OOo 3.2.1 on ubuntu 10.4, MsWXP, MsW2k
PeaceByJesus
Posts: 88
Joined: Mon Dec 24, 2007 7:38 pm

Re: [Solved] How-search and bracket every italized word

Post by PeaceByJesus »

Better all the time. ([^ ]+([ ]?[^ ]+)+) with [$1] (using regular expressions, with format>italics) places brackets around all the italicized words perfectly. And it brackets 2 or more italicized words together, not individually. It does not differentiate btwn words and numbers, but that's not a real problem. Thanks. As for cPOSIX classes, that's beyond me!
Windows 11 Pro, Ryzen 3 3200G CPU; 64GB RAM
Grace and peace thru Jesus the Lord. peacebyjesus.net (pages created in Open office)
Post Reply