I am working with a text where all “\n”s have been deleted (which merges two words into one, like “I like bananasAnd this is a new line.And another one.”) What I would like to do now is tell Python to look for combinations of a small letter followed by capital letter/punctuation followed by capital letter and insert a whitespace.
I thought this would be easy with reg. expressions, but it is not – I couldnt find an “insert” function or anything, and the string commands seem not to be helpful either. How do I do this?
Any help would be greatly appreciated, I am despairing over here…
Thanks, patrick
Try the following:
For example:
If you want to insert a newline instead of a space, change the replacement to
r"\1\n\2".