You don’t need regular expressions. Python has a built-in string method that does what you need:
mystring.replace(" ", "_")
More Related Contents:
- What does += mean in this context?
- Most efficient way to build single-element list from string with or without spaces? [closed]
- How to convert a string in the desired manner?
- Why does comparing strings using either ‘==’ or ‘is’ sometimes produce a different result?
- How to search and replace text in a file?
- Convert hex string to int in Python
- Stripping everything but alphanumeric chars from a string in Python
- How to display a float with two decimal places?
- Convert JSON string to dict using Python
- Print string to text file
- How can I do multiple substitutions using regex?
- What’s the difference between str.isdigit, isnumeric and isdecimal in python?
- How to match any string from a list of strings in regular expressions in python?
- Extract email sub-strings from large document
- Math operations from string [duplicate]
- How can I remove duplicate words in a string with Python?
- Does Python do slice-by-reference on strings?
- How do you extract a url from a string using python?
- Removing list of words from a string
- Safely evaluate simple string equation
- Strip spaces/tabs/newlines – python
- How to print like printf in Python3?
- Replacing specific words in a string (Python)
- How to change a string into uppercase
- Remove all newlines from inside a string
- How can I check if a string has a numeric value in it in Python? [duplicate]
- Python string operation, extract text between html tags
- get python dictionary from string containing key value pairs
- Mutable and Immutable Strings in python
- Detect whether a Python string is a number or a letter [duplicate]