How to replace whitespaces with underscore?

You don’t need regular expressions. Python has a built-in string method that does what you need:

mystring.replace(" ", "_")

Leave a Comment