Ask Your Question
0

Find and replace text with a line break in the middle?

asked 2020-10-21 03:06:53 +0100

dcs1001 gravatar image

updated 2020-10-21 07:56:53 +0100

I have many instances of text that look like:

...blah blah "
            + "blah blah...

And I'm trying to turn it into:

...blah blah blah blah...

I can identify the end of the first line just fine with: "$
And I can identify the beginning of the second line just fine with: ^\s{0,20}\+\s"

But of course combining them into one expression doesn't work, since $^ is probably nonsensical in regex. And if I try to replace them with empty separately, the CrLf persists. Any ideas or is this just not possible? Thx

edit retag flag offensive close merge delete

Comments

Perhaps, you should take a look at the code of OOoFBTools, the JoinBreakLine module (or just use the extension).

gabix gravatar imagegabix ( 2020-10-21 08:09:17 +0100 )edit

2 Answers

Sort by » oldest newest most voted
0

answered 2020-10-21 08:09:33 +0100

ajlittoz gravatar image

Built-in Edit>Find & Replace operates at most on a paragraph. Paragraph breaks are considered delimiters and are outside of the operating range. ^ is the paragraph mark preceding but not included the target pattern and $ is the one following but not included the target pattern.

Consequently, as you guessed $^ does not make sense because it means "the position at end of the paragraph followed by the position before the same paragraph".

^$ is a special pattern to find empty paragraphs. This pattern can be replaced by "nothing", effectively deleting the paragraph mark.

In case your line wrap is caused by a line break (Shift+Enter) instead of a regular paragraph break (Enter), it does not create a paragraph break (as the name implies), the line break can be replaced with a regular expression like:

 ' "\n\s{0,20}\+\s"'  ==> ' '

(quotes added to make the spaces visible).

Otherwise, you have two possibilities:

  • You didn't describe the characteristics of the sequences you want to transform. They look like some programming snippets, meaning they were copied from some source file (in format .txt or the like). It is then easier to process these files before extracting the bits and pasting them into Writer. You can do that easily with sed, awk, perl, grep or even bash or combination of them.

  • Install AltSearch extension which is not limited to a single paragraph and may cross paragraph boundaries.

To show the community your question has been answered, click the ✓ next to the correct answer, and "upvote" by clicking on the ^ arrow of any helpful answers. These are the mechanisms for communicating the quality of the Q&A on this site. Thanks!

edit flag offensive delete link more

Comments

@ajlittoz: AltSearch worked for me, thx. The regex was "\p\s{0,20}\+\s" . Your intuition was correct, this is a Java <string,integer>Hashmap that got way, way, way too big and needed to be put into a SQL tbl. Thanks again.

dcs1001 gravatar imagedcs1001 ( 2020-10-21 10:12:03 +0100 )edit
0

answered 2020-10-21 05:22:55 +0100

luber1 gravatar image

if you're looking to concatenate text in 2 cells, say, try =cell1 &" " & cell2

edit flag offensive delete link more

Comments

Note this question is tagged Writer; and the question possibly could have been phrased as "How do I replace a line break with a space?"

robleyd gravatar imagerobleyd ( 2020-10-21 07:17:53 +0100 )edit

@robleyd: replacing a line break is relatively easy but a paragraph mark in this context can't.

ajlittoz gravatar imageajlittoz ( 2020-10-21 07:46:49 +0100 )edit

luber1: thanks for helping, but this is actually a writer regex question. robleyd: you're right, I should have included find and replace in the question title. I think I might be able to edit it.

dcs1001 gravatar imagedcs1001 ( 2020-10-21 07:56:19 +0100 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2020-10-21 03:06:53 +0100

Seen: 61 times

Last updated: Oct 21 '20