How do I strip all the spaces in a python string? For example, I want a string like strip my spaces to be turned into stripmyspaces, but I cannot s
strip my spaces
stripmyspaces
Try a regex with re.sub. You can search for all whitespace and replace with an empty string.
re.sub
\s in your pattern will match whitespace characters - and not just a space (tabs, newlines, etc). You can read more about it in the manual.
\s