The second one by the regular expression is working in a different way. It's search for duplicated spaces and remove them. The difference between the two is that the leading and ending spaces will be preserved in the second case: