I want to replace whitespace with underscore in a string to create nice URLs. So that for example:
JavaScript
x
2
1
"This should be connected"
2
Should become
JavaScript
1
2
1
"This_should_be_connected"
2
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
1
2
1
mystring.replace(" ", "_")
2