python re.sub
时间: 2023-11-01 22:43:19 浏览: 102
re.sub() is a method in Python's built-in re module that is used to replace one or more occurrences of a pattern in a given string with a replacement string.
Syntax:
re.sub(pattern, repl, string, count=0, flags=0)
Parameters:
- pattern: A regular expression pattern that is to be searched in the string.
- repl: A string that is to be replaced for each occurrence of the pattern.
- string: The input string in which the pattern is to be searched.
- count (optional): Maximum number of occurrences to be replaced.
- flags (optional): One or more optional flags that modify the behavior of the search.
Return Value:
Returns a new string with all the occurrences of the pattern in the input string replaced with the replacement string.
阅读全文