djrip
June 8, 2026, 9:33am
1
Some time ago I made a post (Original below) where I was seeking to convert anything with dots / periods after letters in the name to a one that still included the dots but also added the same word without, so
R.O.C.K. In The U.S.A became ->
ROCK (R.O.C.K) In The USA (U.S.A)
I originally came up with a very complex solution involving temp strings, variables, etc. Now here's the regex version that involves 2 simple Replace With Regular Expressions
The 1st regex converts it to the desired format but adds trailing dots/periods, so the second regex removes / swaps it.
Expression 1: Captures any word up to 9 characters of X. (Additional letters added by "((\w)\.?)?"
((\w)\.)((\w)\.)((\w)\.?)((\w)\.?)?((\w)\.?)?((\w)\.?)?((\w)\.?)?((\w)\.?)?((\w)\.?)?
Used in Replace With Regular Expressions as:
$upper($2$4$6$8$10$12$14$16$18) $upper(($2.$4.$6.$8.$10.$12.$14.$16.$18))
Expression 2:
\.+\) 'Captures any number of \. before a \)
Used in Replace With Regular Expressions as:
\)
Thank. Hadn't thought of the replace and use period.
That I can use. But still at a loss for the X.Y.Z.Z.Y to ==> XTZZY (X.Y.Z.Z.Y)
I'll keep looking
I've played with this a bit since I enjoy writing regex.
The solution I've come up with is a single regex.
Regex:
((?:([A-Z])\.([A-Z])\.(?:([A-Z])\.)?(?:([A-Z])\.)?(?:([A-Z])\.)?(?:([A-Z])\.)?(?:([A-Z])\.)?(?:([A-Z])\.)?(?:([A-Z])\.)?))
Replace with:
$2$3$4$5$6$7$8$9$10 ($1)
I've added a minimum length of 2 letters so it matches 2-9 uppercase letters in a row, each followed by a dot.
The only caveat is that the last letter also has to be followed by a ., otherwise it's not caught (see U.S.A. vs U.S.A below).
Here's what I've tested it with:
djrip
June 10, 2026, 7:51am
3
That's pretty nice & clean. The caveat is a bit of an issue for me. Some files don't have the required End DOT.
I did a whole bunch of testing and reconfiguring after this post, then read your post. I modifed and used your code in the solution.
** I changed the initial key expression to LetterDOTLetter.
** This changed the focus from Letter DOT... to DOT Letter... So once it finds the Key Expression, it only looks for the DOT Letter
** I appended an optional DOT at the end in the modified Regex of yours. This means you don't need a second line to take it out in ACTIONS.
** Kept/added/modified/deleted conditions in your code to avoid X.X. Surname. eg: F.R. David
** Changed to allow lower case. eg: in B.o.B
New Code:
((?:([A-Z])\.([A-Za-z])(?![a-z]|\s[A-Za-z]|\.\s[A-Za-z])(?:\.([A-Za-z]))?(?:\.([A-Za-z]))?(?:\.([A-Za-z]))?(?:\.([A-Za-z]))?(?:\.([A-Za-z]))?(?:\.([A-Za-z]))?(?:\.([A-Za-z]))?(?:\.([A-Za-z]))?)|([A-Za-z])\.([A-Za-z])(?:(?=\.$)|(?=$)))\.?
Thanks for your idea.