RegEx - how to replace a carriage return

Discuss the word processor
Post Reply
franc
Posts: 21
Joined: Sat Oct 08, 2011 2:12 pm

RegEx - how to replace a carriage return

Post by franc »

Hallo

I am trying to replace with a Regular Expression some numbers with carriage return (also called paragraph breaks) to nothing but it aint working.
This is examplarily my text:
Blabla
1
blabla
blablablabla
2
blabla blabla
12
blabla
13
basdaf
asdfasd
14
asdfa
where I want to eliminate the numbers (these were page numbers, hardcoded ones) but also the carriage returns (such ones done with Return without Space).
I could easily find and replace with nothing the numbers, no problem, but then I have left some empty lines.
In normal RegEx I would go for the hex value, e.g.:
Search with Regex:

Code: Select all

\x0A
and combine it with the numbers, e.g.

Code: Select all

\x0A\d{1,2}
but this (\x0A) doesnt find the carriage returns on my Mac OS 10.11.6 with OO 4.1.5

So neither are working \n nor \x00A nor \x000A nor \x0D\x0A - I tried a lot.

I found in some post the $ (which is in normal RegEx just the line end, without any length!) but this is not helping, because I can not eliminate the carriage return, I can just find a line's end.

So how can I find and replace the real carriage return character with regex on Mac OS 10.11.6 and OO 4.1.5?

The digits I easily can find, but only not the carriage return.
The line break (with Space+Retrurn) I can find with \n

Thanks.

frank

PS.: I asked that in a german openoffice forum before and got there the hint to ask here.
OpenOffice 3.3
User avatar
Zizi64
Volunteer
Posts: 11361
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: RegEx - how to replace a carriage return

Post by Zizi64 »

The digits I easily can find, but only not the carriage return.
The line break (with Space+Retrurn) I can find with \n
You can find and replace the CR signs with the AltSearch extension.
https://extensions.libreoffice.org/exte ... for-writer
https://extensions.openoffice.org/en/pr ... -altsearch

But it not a good idea to replace ALL of the CR-s from a document, because the paragraphs have a character number limit...
Last edited by Zizi64 on Wed May 02, 2018 6:42 am, edited 2 times in total.
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.
FJCC
Moderator
Posts: 9279
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: RegEx - how to replace a carriage return

Post by FJCC »

Does it work to eliminate the numbers and then search for empty paragraphs with ^$
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
franc
Posts: 21
Joined: Sat Oct 08, 2011 2:12 pm

Re: RegEx - how to replace a carriage return

Post by franc »

Zizi64 wrote:...
You can find and replace the CR signs with the AltSearch extension.
...
That is not working on my mac (on PC no problems), see attached Screenshot.
Zizi64 wrote:...
But it not a good idea to replace ALL of the CR-s from a document, because the paragraphs have a character number limit...
No problem to replace two CRs with just one, my problem is, that there are one too much, so I have an empty line.
Attachments
AltSearch Dialog
AltSearch Dialog
OpenOffice 3.3
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: RegEx - how to replace a carriage return

Post by Villeroy »

^[[:digit:]]+$ finds paragraphs that consist of digits.
Replace them with nothing and then replace the empty paragraphs ^$ with nothing.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
franc
Posts: 21
Joined: Sat Oct 08, 2011 2:12 pm

Re: RegEx - how to replace a carriage return

Post by franc »

Thank.
But this is not possible as solution, because there are other empty paragraphs which are indeed wanted.
I need to replace in one go.
OpenOffice 3.3
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: RegEx - how to replace a carriage return

Post by Villeroy »

Apply correct spacings between paragraphs instead of blank paragraphs?
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
franc
Posts: 21
Joined: Sat Oct 08, 2011 2:12 pm

Re: RegEx - how to replace a carriage return

Post by franc »

Yes
OpenOffice 3.3
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: RegEx - how to replace a carriage return

Post by Villeroy »

Well, then remove all blank paragraphs and apply paragraph styles. Style "Text Body" for instance, includes some extra spacing.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Post Reply