I want to replace whitespace with underscore in a string to create nice URLs. So that for example:
\"This should be connected\" becomes \"This_should_be_conn
Using the re module:
import re
re.sub('\s+', '_', "This should be connected") # This_should_be_connected
re.sub('\s+', '_', 'And so\tshould this') # And_so_should_this
Unless you have multiple spaces or other whitespace possibilities as above, you may just wish to use string.replace as others have suggested.