![]() |
#1 |
Perfectionist
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 72
Karma: 12802
Join Date: Apr 2014
Device: none
|
Removing double space
I have a text riddled with double spaces between words. I'm using \w__\w to find the instances and it works OK, but I don't know what to put in the replace field.
For example, I'd like to replace "was__not" with "was not" using a regular expression. Anyone? |
![]() |
![]() |
![]() |
#2 |
Ex-Helpdesk Junkie
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 19,421
Karma: 85400180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
|
Find: \s{2,}
Replace: <--This is an invisible space. But then you have to prettify everything. This is one of those things that exclsively affects coder typography senses ![]() I would like this to be in Beautify, but Kovid nixed that because crazy people might be using CSS to render consecutive whitespace. ![]() Last edited by eschwartz; 01-26-2015 at 10:27 PM. |
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 24,905
Karma: 47303824
Join Date: Jul 2011
Location: Sydney, Australia
Device: Kobo:Touch,Glo, AuraH2O, GloHD,AuraONE, ClaraHD, Libra H2O; tolinoepos
|
Or:
Find: (\w) (\w) Replace: \1 \2 |
![]() |
![]() |
![]() |
#4 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 4,520
Karma: 121692313
Join Date: Oct 2009
Location: Heemskerk, NL
Device: PRS-T1, Kobo Touch, Kobo Aura
|
Why would you want to replace that? A double space would be rendered as one anyway. That is, unless at least one of the spaces is not a real space, but for example a non-breakable space. In that case I am not sure the proposed regex would catch those.
|
![]() |
![]() |
![]() |
#5 |
Ex-Helpdesk Junkie
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 19,421
Karma: 85400180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
|
Code typography nuts, like I said.
![]() |
![]() |
![]() |
Advert | |
|
![]() |
#6 |
Well trained by Cats
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 31,047
Karma: 60358908
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
|
|
![]() |
![]() |
![]() |
#7 |
Ex-Helpdesk Junkie
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 19,421
Karma: 85400180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
|
The difference should be largely offset by compression?
![]() |
![]() |
![]() |
![]() |
#8 | |
Perfectionist
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 72
Karma: 12802
Join Date: Apr 2014
Device: none
|
Well, this is odd.
That's exactly what I'd tried before asking the question. RegEx Mode ON. All spaces in place. It didn't work. Now it does ![]() Anyway, davidfor, thanks! Quote:
![]() I like the code to be clean, too, not only the visible text. I see no harm in that. |
|
![]() |
![]() |
![]() |
#9 |
Fanatic
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 515
Karma: 1470724
Join Date: Jul 2013
Location: Quebec CA
Device: android 4 (samsung tablet and asus tablet)
|
When something bugs me enough I get into the code and painstakingly change every instance of the problem.
One problem I see with Find: (\w) (\w) Replace: \1 \2 is that it appears to me to be finding two white spaces and replacing both. Could one of the problems be if the white space is a tab? When you look at it in edit are you seeing two spaces? or a ? I find that the more specific you are the easier it is to correct. One last thought... is the css justifying the lines causing the appearance of larger spaces? |
![]() |
![]() |
![]() |
#10 | |
Well trained by Cats
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 31,047
Karma: 60358908
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
|
Quote:
Code:
(\w)[[:space:]]{2,}(\w) |
|
![]() |
![]() |
![]() |
#11 |
Ex-Helpdesk Junkie
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 19,421
Karma: 85400180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
|
That would be why post #2 was my suggestion to use "\s{2,}"
![]() Or for that matter, "(\s| ){2,}" |
![]() |
![]() |
![]() |
#12 | |
Perfectionist
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 72
Karma: 12802
Join Date: Apr 2014
Device: none
|
Quote:
Well, yes, it does so here and there, depending on the letter count in a row. But upon opening a book in the editor, one can easily determine if it is just an appearance or a real problem. |
|
![]() |
![]() |
![]() |
#13 |
Member
![]() Posts: 17
Karma: 10
Join Date: Nov 2014
Device: Samsung Note
|
I search for (spacebar)(spacebar)+ in Regex
You could also use (spacebar){2,} ( (spacebar) means tap the space bar, don't type the word in! ![]() Either way means you are looking for two or more spaces. *** Another Regex that I use all the time (usually just before the one above) is Search: \n replace: (spacebar) That removes ALL line feeds & replaces them with spaces. After I've done the two operations above, I Beautify all files, which puts in only the necessary line feeds. |
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
How do I get a double space between paragraphs? | ficbot | Sigil | 7 | 07-17-2013 09:12 PM |
Want double-space between sentences | GrannyGrump | Sigil | 11 | 05-28-2011 10:47 AM |
Students with a .edu address can get double referral space on Dropbox | cheyennedonna | enTourage Archive | 5 | 01-12-2011 09:59 AM |
What is the double space trick? | Jabby | Calibre | 18 | 08-29-2010 09:48 PM |
Double chapter break when removing first image | tochill | Calibre | 0 | 03-04-2010 07:41 PM |