Ask Your Question

Find/replace only first word in every paragraph [closed]

asked 2014-06-27 11:31:35 +0100

dmitry.shishkov.18 gravatar image

updated 2014-06-27 13:00:25 +0100

Hello! Well the name of the topic says it all. Is it possible to achive with regular expressions. I know that "^." will search for the first character in every paragraph but what about words? Thank you for the help in advance.

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Alex Kemp
close date 2016-02-27 12:09:49.420474

4 Answers

Sort by » oldest newest most voted

answered 2014-06-27 13:58:46 +0100

Lupp gravatar image

updated 2014-07-03 20:44:11 +0100

You asked for Calc! There should be other means. Use formulae to split your information into different cells.

For Writer: You may use 'Find & Replace' as shown in the attached example.


'Search for': ^([\w]+)\W(.+$)

'Replace with': $1\n$2

'Regex' ON

ONLY ONE PASS (like 'Replace All', of course!

For further information refer to RegEx tutorials.

[begin EDIT]

This is strange. My answer above and the eaxample I had attached do no longer meet the question. Some more puzzles are connected to this.

The comment by @mahfiaz- "Also, regex searches work just fine in Calc as well." from today seems mislead because it doesn't match the original need of inserting an extra paragraph - which cannot be done inside a cell content by \n. (mahfiaz' comment concerning [...] is correct.)

As far as I can remember the original question aimed to transforming the first word of a multiword paragraph (in specific the first name of a full US style name) into an extra paragraph. This is exactly what my answer is achieving and what is demonstrated by the first example in my attachment. It is also that what cannot be done for a spreadsheet cell. The question as it is given now does completely miss this situation.

Did someone change the original first post? Should I seek medical advice? Was there another question I might have inadvertently "answered" under the wrong topic? Who does remember?

What about @blindape-'s answer? It is also mentioning "name" and talking of inserting a line break?

[end EDIT]

edit flag offensive delete link more


\w+ does not need surrounding [] (although they don't hurt).

Also, regex searches work just fine in Calc as well.

mahfiaz gravatar imagemahfiaz ( 2014-07-03 10:25:05 +0100 )edit

answered 2014-06-27 11:54:19 +0100

lactea gravatar image

updated 2014-06-27 11:54:50 +0100

I do not know if this works out for you, but there is an extention that might be worth a shot:

There you can

Search out block of paragraphs delimited by two text marks


Searching similarly or the same manually formatted part of text, according to cursor point

edit flag offensive delete link more


Thank you for the answer. This one may be helpful but it is only for Writer but I am having a spreadsheet in Calc.

dmitry.shishkov.18 gravatar imagedmitry.shishkov.18 ( 2014-06-27 12:09:06 +0100 )edit

Okay, it was not clear to me. I've thought paragraph refers to Writer.

lactea gravatar imagelactea ( 2014-06-27 14:58:38 +0100 )edit

answered 2014-07-03 09:29:45 +0100

blindape gravatar image

Since your data is in Calc you can use the following formula to convert the first space into a line break: =SUBSTITUTE(A1;" ";CHAR(10);1)

The SUBSTITUTE function searches for a piece of text in a cell and replaces it with another piece of text. SUBSTITUTE has 4 arguments.

1) Cell or piece of text to search in. I this example i assume your original name is in A1.

2) Piece of text to search for. Always enclose text in speachmarks in formulas. There is a space between the speachmarks in the above formula.

3) The new text to replace the item found in argument 2. The above formula uses CHAR(10) to create a line break. The CHAR function returns the character represented by the character code enclosed in the brackets. I believe 10 is the code for a carriage return which produces a line break in the cell.

4) the last argument is possibly the most important in your situation. It represents which instant of argument 2 you wish to replace. If left blank, it replaces every instance of argument 2 it finds. By setting this argument to 1 only the first space in the name is replaced with a line break.

Once you have created the formula and copied it down your data, you can then copy the formula cells and use the Pasre Special... dialog to paste as text over the original values. Personally i prefer to keep the original data column in tact in case the data needs to be changed.

Cheers, John

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2014-06-27 11:31:35 +0100

Seen: 1,245 times

Last updated: Jul 03 '14