I’m not sure how do this, as I’m pretty new to regular expressions, and can’t seem to find the proper method to accomplish this but say I have the following as a string (all tabs, and newlines included)
1/2 cup
onion
(chopped)
How can I remove all the whitespace and replace each instance with just a single space?
This is a case where regular expressions work well, because you want to treat the whole class of whitespace characters the same and replace runs of any combination of whitespace with a single space character. So if that string is stored in
s, then you would do: