re.sub
Return the string obtained by replacing the leftmost non-overlapping occurrences of pattern in string by the replacement repl.
re.sub(pattern, repl, string, count=0, flags=0)
pattern
The regular expression to search for.
repl
The replacement string or a function.
count
The maximum number of substitutions (0 for all).
flags
Flags that modify the expression`s behavior.
Examples
>>> import re
>>> re.sub(r'\s+', '-', 'hello world')
'hello-world'