View Single Post
Old 12-22-2021, 10:52 AM   #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 questions for Acronyms - small issue

Current book I'm cleaning up has 100s of instances of acronyms, 2 - 6 letters, with periods between them and I'd like to just have the letters without the periods.

I made 5 pairs of saved searches, one version with a trailing space and one without since that seems to be a common construction for 2, 3, 4, 5, and 6 char acronyms

e.g. A.B.C.D.E.F.space and just A.B.C.D.E.F.

Case 1 - If there's a space, then I figure it's inside a paragraph and I just want ABCDEF blah blah

Case 2 - If there's NOT a space, then I figure it's at the end of a paragraph and I want ABCDEF. Blah blah

So for Case 1

Find: (has trailing space)

Code:
([A-Z])\.([A-Z])\.([A-Z])\.([A-Z])\.([A-Z])\.([A-Z])\.
Replace: (also with trailing space

Code:
\1\2\3\4\5\6

and for Case 2

Find: (NO trailing space)

Code:
([A-Z])\.([A-Z])\.([A-Z])\.([A-Z])\.([A-Z])\.([A-Z])\.
Replace: (NO trailing space, but period instead

Code:
\1\2\3\4\5\6.
I have to be careful to run them in order:6+space, 6-no space, 5+space, 5-no Space, .... otherwise substrings would get replaced

I figure that there HAS to be a more intelligent way to set up these searches, and hopefully someone can suggest an idea

Last edited by phossler; 12-22-2021 at 09:46 PM.
phossler is offline   Reply With Quote