We will be migrating from Ask to Discourse on the first week of August, read the details here

# How can I find/replace double spaces NOT after punctuation? [closed]

I am currently using LibreOffice Version: 3.6.2.2 and my question pertains to Writer.

Due to reformatting and changing some paragraphs throughout my 511 page manuscript, there are now double spaces in the middle of sentences. I believe that it may have been due to having accidentally hit the space bar twice after writing the last word on a line and before writing the next word in the sentence which starts a new line. Quite likely could be from formatting the page to a different size for print so the lines changed length and now I have multiple spaces between two words in mid-sentence.

I have been trying to formulate a regular expression to search for exactly what I am trying to find but so far it will replace ALL double spaces which includes following punctuation. I realize that a lot of people are discussing whether or not they should use single or double after punctuation. But my first novel used double spacing and I want to keep that going in this, my second novel.

I am trying to come up with the appropriate regular expression to find two (or more) consecutive spaces that follow text/does not follow punctuation. Any help would be greatly appreciated as 511 pages is a lot to get through in fairly quick order and I feel that there is too good a likelihood that I will miss some no matter how vigilantly I look. Thanks 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-25 00:15:06.996650

Sort by » oldest newest most voted

Mind the spaces! Make sure 'Regular expressions' is checked in 'Find & Replace'.

Search for (2 spaces in front of the "+"):

"([^\.,])  +"

Replace with (1 space behind "$1"): "$1 "

Don't enter the quotation marks. (Other solutions will be possible)

Example

Alarich ging zu Berta,  nicht ahnend, dass Cuno schon dort war.  Da gab es Tee mit Kuchen. Aber das schmeckte nicht.

Unprocessed copy:

Alarich ging  zu Berta,  nicht ahnend, dass   Cuno schon  dort war.   Da  gab es Tee mit  Kuchen. Aber das schmeckte nicht.

[begin Edit1] I thought too late of the tool "preformatted text". Therefore I had to ensure the second space in front of "+" in a second step. If you want to also delete trailing spaces behind a comma just leave the comma out in 'Search for'. [end Edit1]

more

Dude, I think you just saved me! I submitted the manuscript for my second novel which is slated for release this Thursday. I got my proof copy and it was perfect except I noticed that somehow there were all these spots throughout the printed proof copy. I have a little more checking to do to make sure that it fully did the trick but it appeared to! Now I don't have to check all 511 pages by hand and potentially miss some! And now I can submit the changes to have it released in time!

( 2014-06-09 22:30:41 +0200 )edit

@christophermichael.snyder - you'll need to watch for question marks, exclamation marks, quotation marks, etc. - i.e., other "boundary" puctuation that should have the double-space on your system (I expect).

( 2014-06-09 22:37:42 +0200 )edit

Here's another possibility - ensure "Regular Expressions" are enabled for your CTRL + H search, then:

• Search =
([:alnum:])([:space:][:space:])
• Replace string =
\$1

This uses "grouping", i.e., the parentheses, to give you "back references" for replacing. [:alnum:] represents any alphanumeric character (therefore excluding punctuation); [:space:] stands for "space". ;) The replace says "keep the string found in the first hit, but replace the second hit (2 spaces) with one space".

Usage notes:

• That search string is limited to precisely two spaces, of course. To search for two-or-more, change the middle parentheses to ([:space:][:space:]+) adding the "+" sign.
• You probably want to include close-brackets in your search, though? If so, then alter the first "group" to ([[:alnum:]\)\]])([:space:][:space:]+) - hopefully that example gives the idea if you think of other non-alphanumeric characters that could precede the double-space.
• See this earlier Q&A on spaces after full-stops ("periods") for more information and links.
more

Thanks david, I had already run Lupp's suggestion and therefore I did not get any hits on yours but that could quite likely be because there weren't any left. But I wanted to see. Your example also makes a lot of sense to me. I am more used to Object Oriented Programming regexes so i was thinking along the same lines that he was. So you taught me about the alnum which can always come in handy for various reasons. thank you for also taking the time to reply!

( 2014-06-09 22:36:49 +0200 )edit

@christophermichael.snyder - thanks for comment. :) Always a help to see various solutions! See also my comment to Lupp's solution as it could potentially be over-eager, which was why I offered an alternative. Good to have 'em both!

( 2014-06-09 22:40:34 +0200 )edit

Greedy regexes! Luckily so far ALL punctuation seems to still have two spaces but if I see a change in that then I already know why. I do not have to worry about spaces following quotations as my writing style has each sentence/paragraph of a section of dialogue as a chunk of dialogue. So I almost never would have ' "I like to run." Said Peter"' In my style I WOULD have double space after quotes but I have none of that hah

( 2014-06-09 22:54:02 +0200 )edit

## Stats

Asked: 2014-06-09 20:10:52 +0200

Seen: 4,635 times

Last updated: Jun 09 '14