Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Sigil

Notices

Reply
 
Thread Tools Search this Thread
Old 12-10-2022, 02:08 AM   #1
Dashcroft
Junior Member
Dashcroft began at the beginning.
 
Posts: 3
Karma: 10
Join Date: Dec 2010
Device: Kindle Scribe
Regex expression to replace certain spaces with nonbreaking spaces

Hi,
I would like to automatically find and replace the spaces in "T. S. Eliot", "D. H. Lawrence", "F. R. Leavis" and similarly patterned names with non-breaking spaces. I've tried:

Find:
Code:
[A-Z]\.\s
Replace:
Code:
\g<0>&#nbsp;
But that still leaves the spaces in. What am I doing wrong and what might help in this case?
Dashcroft is offline   Reply With Quote
Old 12-10-2022, 02:15 AM   #2
Tex2002ans
Wizard
Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.
 
Posts: 2,297
Karma: 12126329
Join Date: Jul 2012
Device: Kobo Forma, Nook
Quote:
Originally Posted by Dashcroft View Post
I would like to automatically find and replace the spaces in "T. S. Eliot", "D. H. Lawrence", "F. R. Leavis" and similarly patterned names with non-breaking spaces.
I explained all of this (and other examples) in extreme detail in:

- - -

Side Note: If you wanted even more fantastic regex tips/tricks, see my posts a few months ago in:

I linked to a ton of the previous topics + step-by-step breakdowns of helpful regular expressions.

- - -

Quote:
Originally Posted by Dashcroft View Post
What am I doing wrong and what might help in this case?
And may I ask why you're trying to use NBSPs in your ebooks? Is there any specific reason or issue you were trying to solve?

Last edited by Tex2002ans; 12-10-2022 at 02:18 AM.
Tex2002ans is offline   Reply With Quote
Advert
Old 12-10-2022, 02:57 AM   #3
Dashcroft
Junior Member
Dashcroft began at the beginning.
 
Posts: 3
Karma: 10
Join Date: Dec 2010
Device: Kindle Scribe
Thank you very much for pointing me to the right thread! I'll go with:

Find:
Code:
([A-Z])\. ([A-Z])\. ([A-Z])
Replace:
Code:
\1.\xA0\2.\xA0\3
and replace "xA0" with the appropriate code for a nonbreaking space in Calibre.

That seems to suit me perfectly.

Since you asked, I just don't like line breaks after the first or second initial when I read a book on my Kindle.
Dashcroft is offline   Reply With Quote
Old 12-10-2022, 08:01 PM   #4
DNSB
Bibliophagist
DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.
 
DNSB's Avatar
 
Posts: 36,369
Karma: 145735554
Join Date: Jul 2010
Location: Vancouver
Device: Kobo Sage, Libra Colour, Lenovo M8 FHD, Paperwhite 4, Tolino epos
Quote:
Originally Posted by Dashcroft View Post
and replace "xA0" with the appropriate code for a nonbreaking space in Calibre.
For what it's worth, &#xa0; is the same as & #160; and &nbsp;. HTML5 which the basis for Epub3 CSS deprecated all but the big 5 named entities so you would have to explicitly define any named entities other than &quot;, &apos;, &amp;, &lt;, &gt;.
DNSB is online now   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Writing spaces for regex roger64 Sigil 10 12-05-2017 09:26 PM
How to make regex to replace 2 spaces between words, with one space? crankypants Sigil 4 10-29-2015 11:51 AM
regex - issue with spaces? cybmole Editor 43 12-31-2013 12:49 PM
Regex Find and Replace - Spaces essayhead Sigil 2 08-10-2012 07:41 PM
Regular Expression: does not replace with spaces murphycc Conversion 3 02-11-2012 01:31 PM


All times are GMT -4. The time now is 03:52 PM.


MobileRead.com is a privately owned, operated and funded community.