in reply to simpler regex
That's because a regular expression will only ever match once for every character position in a string, and no character that has been part of a previous match will be part of the next match. Let's use a different example to make talking easier:
"X Y Jones"
The space between X and Y does double duty, once as "end marker" of X and once as "start marker" of Y, but as it has already been used up as end marker, it won't be looked at again for the next start marker.
I see two possible ways forward - either use lookahead to check for a space and not match it, like /(?=\s|$)/ or use the \b word boundary marker, which introduces other problems though:
s/\b([A-Z])\b/$1./g
will also do replacements for O'Reilly, A-J or other stuff. So, depending on your input data, that may be unwanted.
|
|---|