[Solved] Find and replace space and paragraph characters

Discuss the word processor
Post Reply
HaRo
Posts: 9
Joined: Tue May 21, 2019 6:30 am

[Solved] Find and replace space and paragraph characters

Post by HaRo »

I lost my MS Office in disk mishap. I'm trying OO. A problem. I frequently collect a block of words separated by 4 or 5 spaces.

1. Using MS Word, I find double space (put cursor into find box and press space bar twice) and replace with single space (put cursor into replace box and press space bar once.) Replace all. Repeat till words are only separated by a single space.
2. Then I convert to a list. Find space (put cursor into find box and press space bar once) and replace with paragraph (put cursor into replace box and type ^p).
3. Then sort into alphabetical order.
4. Change list to block. Find paragraph mark (put cursor into find box and type ^p) and replace with five spaces (put cursor into replace box and press space bar five times.)

How do I do the equivalent thing with OO? I can do the sorting, but not the rest of it.
Last edited by Hagar Delest on Sun May 26, 2019 12:47 pm, edited 1 time in total.
Reason: tagged solved
Open Office 4.1.6 on Windows 7
User avatar
RoryOF
Moderator
Posts: 34586
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: find and replace space and paragraph characters

Post by RoryOF »

Your step 1 is OK
Step 2, Find a space, Replace \n and ensure "More options" is set to "Regular Expressions"
Step 3 should be OK
Step 4, Find $, Replace a space, "More options" set to "Regular Expressions"

Above sequences just now tested and working correctly.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
HaRo
Posts: 9
Joined: Tue May 21, 2019 6:30 am

Re: Find and replace space and paragraph characters

Post by HaRo »

Thanks, but step 1 didn't work. I set up a block of words with varying numbers of spaces between them. Put five spaces into find box, one into replace box. It replaced all the fives with one. Then I put two into Find box, left one in replace box. Got "search key not found", even though there were plenty of places with multiple spaces. Tried with four spaces (since there were some words separated only by four spaces) and the same thing happened.
Open Office 4.1.6 on Windows 7
User avatar
RoryOF
Moderator
Posts: 34586
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Find and replace space and paragraph characters

Post by RoryOF »

If I am faced with multiple spaces I normally Find two spaces, replace with one space (no need for Regular experessions option in this case) and run that search repeatedly until "not found". Try again with "Regular Expressions" not checked

I am not driving your computer: as I wrote, my sequence had been tested with the Find and Replace specifiers I noted.
 Edit: If you are pasting from Internet sources, it is possible (indeed, likely) that what you are seeing as spaces (ASCII character 020H) are "non breaking spaces" (ASCII character 0A0H). Find and Replace does not treat these as equivalent. To disclose them, turn on /View /non printing characters; such non breaking spaces will show as shaded spaces. If so, select one of these, Copy it, then Paste into Find box. Replace with space, press Replace all button. Now Find should continue to find and replace ordinary spaces when you instruct it to do so, 
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
User avatar
Lupp
Volunteer
Posts: 3542
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: Find and replace space and paragraph characters

Post by Lupp »

There are many ways to fine-tune RegEx for such tasks. RegEx are much more powerful than the means MS Word offers (afaik).

Code: Select all

\s
e.g. will accept any kind of whitespace, including tab marks and hard line breaks. Consciously used together with with a quantifier like

Code: Select all

{2,}
with an ordinary space in "Replace with", and with the option "Current selection only" it may help in the present case.
See the attached example. It also contains a bit of additional information.

===Editing; for completeness only===
Paragraph breaks are not accepted by any RegEx in OpenOffice F&R 'Search for' except:
-1- denoted by the special character "$" as a special kind of "zero-length lookahead assertion".
-2- by "$" again like actual characters if a sequence of empty paragraphs shall be addressed.
The whitespace characters accepted by "\s" do not include paragraph breaks.
Attachments
aoo98107FandR_spaces_1.odt
(35.44 KiB) Downloaded 90 times
Last edited by Lupp on Wed May 22, 2019 2:41 pm, edited 3 times in total.
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
User avatar
RoryOF
Moderator
Posts: 34586
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Find and replace space and paragraph characters

Post by RoryOF »

I usually use multiple simple F&R operations, Lupp. Note that your formula, given in the body of your reply, can affect some page style changes, so caution is suggested.
 Edit: I used a copy of an existing document (A5 pages) inserted into a blank Writer document, and failed to notice that the Default style of the blank document was retained (A4 page) rather thsn the Default style (A5 page) used in the inserted document. 
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
erbsenzahl
Volunteer
Posts: 254
Joined: Tue Apr 18, 2017 8:23 am
Location: Germany

Re: Find and replace space and paragraph characters

Post by erbsenzahl »

@HaRo:
Your Swiss knife could be the AltSearch.oxt extension.

When downloaded install it via Tools menu > Extension Manager and start OpenOffice anew.

To replace spaces into paragraphs and return use for paragraph only \p. That's all. As simple as in Word.
LibreOffice current versions 7 and OpenOffice 4.1.15
on LinuxMint 20 - 21 Mate, W10-64 pro
User avatar
RoryOF
Moderator
Posts: 34586
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Find and replace space and paragraph characters

Post by RoryOF »

A possible problem users may find with AltSearch is that compared with OO's F&R it takes a long time in any document of size (hundreds of pages).
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
HaRo
Posts: 9
Joined: Tue May 21, 2019 6:30 am

Re: Find and replace space and paragraph characters

Post by HaRo »

Thanks, erbsenzahl. I'll give it a try.
Open Office 4.1.6 on Windows 7
HaRo
Posts: 9
Joined: Tue May 21, 2019 6:30 am

Re: Find and replace space and paragraph characters

Post by HaRo »

Nope. The first part works fine, both for English and Chinese. I set up a block of words with varying spaces between them, use space bar to put double spaces in find, single in replace, and replace all. Repeat until there is only a single space between them.
But when I put space in find, and \p into replace, it refuses to do anything. I've tried it with end-of-word, any-space, and non-breaking-space from the list. It won't find them, won't replace them.
Open Office 4.1.6 on Windows 7
User avatar
RusselB
Moderator
Posts: 6646
Joined: Fri Jan 03, 2014 7:31 am
Location: Sarnia, ON

Re: Find and replace space and paragraph characters

Post by RusselB »

The following was done using the default OpenOffice Find & Replace dialog in Writer.
This has been briefly tested.
In the Find & Replace dialog put \s+ in the Find section and \n in the Replace section.
Select More Options and ensure the Regular expressions is checked.
My test shows that this finds multiple occurrences of the space character and then replaces them with a single paragraph character.
OpenOffice 4.1.7, LibreOffice 7.0.1.2 on Windows 7 Pro, Ultimate & Windows 10 Home (2004)
If you believe your problem has been resolved, please go to your first post in this topic, click the Edit button and add [Solved] to the beginning of the Subject line.
HaRo
Posts: 9
Joined: Tue May 21, 2019 6:30 am

Re: Find and replace space and paragraph characters

Post by HaRo »

By George, you've got it!

Thanks, RusselB.

On my quick tests, that will do what I want both for English and Chinese!

I can replace multiple places with a single para mark, sort (OO doesn't automatically recognise Chinese, but gives more sorting options for Chinese than MSWord) and the replace the para marks with multiple spaces.

I'll come back and moan some more if I have problems with it, but right now it looks fine.
Open Office 4.1.6 on Windows 7
User avatar
RoryOF
Moderator
Posts: 34586
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Find and replace space and paragraph characters

Post by RoryOF »

HaRo wrote:Nope. The first part works fine, both for English and Chinese. I set up a block of words with varying spaces between them, use space bar to put double spaces in find, single in replace, and replace all. Repeat until there is only a single space between them.
But when I put space in find, and \p into replace, it refuses to do anything. I've tried it with end-of-word, any-space, and non-breaking-space from the list. It won't find them, won't replace them.
When using the \n in either Find or Replace one must use More Options: Regular expressions.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
Post Reply