REAL-WORLD CHALLENGES
Whitespace cleanup
Your first practical substitution: collapse runs of spaces.
Replace every run of two or more spaces with a single space. The pattern matches the run, the replacement is one space. ` {2,}` reads as "a space, two or more times" - so "a b" (three spaces) becomes "a b".
Why two or more, not one or more? Replacing every single space with a space works too, but it touches text that is already fine. Precise patterns make precise edits - it matters once you run substitutions over real files.
Collapse every run of multiple spaces into one space.
s/
->
too many spaces
must become:
too many spaces
already clean
must become:
already clean
a b c
must become:
a b c