Clean up spaces between letters / triple spaces in text string

javascript, php

Solution

preg_replace('/(.) /', '\\1', $string);

The regex engine doesn't match substrings that are the result of a replacement, so it will correctly handle triple spaces without needing to special case them.

Problem

I need to clean up strings of text where every letter has a space in between and every space is composed of 3 spaces, for example: ``` E X C E P T I O N A L C R E A T I V I T Y A N D A T A I L O R E D D E S I G N E D G E ``` How would I go about cleaning the text up, ie - converting every triple-space to a single space, and removing the space in between each letter? Client-side / server side solutions welcome.

Original source