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

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 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

Sort by » oldest newest most voted

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]

more

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

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

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

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

http://extensions.libreoffice.org/ext...

There you can

Search out block of paragraphs delimited by two text marks

and

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

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.

( 2014-06-27 12:09:06 +0100 )edit

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

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

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

more