I recently I ran into a problem in Erlang project and I had to find a way to Remove multiple spaces in string and leave only one one space.

Some string with     extra        spaces.


Here is solution how to remove it with simple re:replace

re:replace("Some string with     extra        spaces.", "(\\s+\\s+)", " ", [global,{return,list}]).

and the returned output is:

Some string with extra spaces.

Useful links: