Tag: regular represents style optional parameter Python lag tin Hello Sub
Features of the 1.re.sub
RE is an abbreviation for regular expression, which indicates regular expressions
A sub is an abbreviation for Substitude, which represents a replacement
Re.sub is a function of regular expressions that implements a more powerful substitution function than a normal string.
eg
Replace vs Re.sub
>>>stri="Hello 111 World 111"
>>>replacestr=stri. Replace ("111", "222") ===> "hello 222 world 222"
If
>>>stri="Hello 123 World 456"
>>>replacedstr = re.sub ("\d+", "222", inputstr) ===> put 123 and 456, switch to 222
Detailed explanations of the various parameters of the 2.re.sub
Re.sub a total of five parameters.
Re.sub (Pattern, Repl, String, count=0, flags=0) Three required parameters: pattern, REPL, string Two optional parameters: count, Flags
Python:re.sub () Implements string substitution