Python Function Reference

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