View Single Post
Old 03-26-2021, 06:05 PM   #1
phossler
Wizard
phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.
 
Posts: 1,087
Karma: 447222
Join Date: Jan 2009
Location: Valley Forge, PA, USA
Device: Kindle Paperwhite
RegEx: Insert nbs between initials, etc.

Looking to see if there is a RegEx that will help to insert non-breaking spaces to join names, etc. so as to avoid a line wrap in the middle

For example. in the fragment below, I'd like to insert NBS after the 's' and before the "B' so that 'Thomas J. Beale' doesn't line wrap

Quote:
by the name of Thomas J. Beale rode into Lynchburg and checked into the Washington Hotel.
I think I'll need two passes

#1 - A. B. Charles -- > A.nbsB.nbsC

Find: ([A-Z])\. ([A-Z])\. ([A-Z])
Replace: \1.\xA0\2.\3

#2 - A. Charles --> A.nbsC

Find: ([A-Z])\. ([A-Z])
Replace: \1.\xA0\2

The problem -- If a sentence ends with an upper case letter, it finds it

blah blah end of sentence T. Next sentence

Is there a better way to do the RE?

Eventually I'd like to extend this to joining dates. Maybe some others

March 22, 2021 --> Marchnbs22,nbs2021
phossler is offline   Reply With Quote