Correcting punctuation spacing in a string
I would split it into three stages, and two concepts.

Conceptually, split the problem into:


String manipulation (reading and writing)
Logical problems (what exists and what needs doing)


The stages the process might be split into:


The first stage involves reading the string, parsing it from beginning to end, recording the logical aspects of what exists.
The second stage involves manipulating the logical record that represents the tokens, transforming it from a representation of what exists, to a representation of what string manipulations are required.
The third stage is executing the string manipulation.