Skip to content
Advertisement

How to replace whitespaces with underscore?

I want to replace whitespace with underscore in a string to create nice URLs. So that for example:

JavaScript

Should become

JavaScript

I am using Python with Django. Can this be solved using regular expressions?

Advertisement

Answer

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

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement