I've got a file whose format I'm altering via a python script. I have several camel cased strings in this file where I just want to insert a single space before the capital letter - so "WordWordWord" becomes "Word Word Word" but I also have some abbreviations as well, Like in the text "General Manager or VP".
I found an answer from David Underhill in this post:
A pythonic way to insert a space before capital letters
While this answer helps me to not insert spaces between abbreviations inside the text like "DaveIsAFKRightNow!Cool"
But it sure inserts a space between V and P in "VP".
I only have 25 experience points and i am unable to comment on the existing post, i am left with no other choice than to create another post for this similar sort of problem.
I am not that good at RegEx and not able to figure how to handle this situation.
I have tried this:
re_outer = re.compile(r'([^A-Z ])([A-Z])')
re_inner = re.compile(r'(?<!^)([A-Z])([^A-Z])')
re_outer.sub(r'\1 \2', re_inner.sub(r' \1\2', 'DaveIsAFKRightNow!Cool'))
It gives me 'Dave Is AFK Right Now! Cool'
My text sample is this:
General Manager or VP Torrance, CARequired education
I want the output as: General Manager or VP Torrance, CA Required education
The Output i am getting is: General Manager or V P Torrance, CA Required education