The examples in this paper describe Python is replacing the string function re.sub usage. Share to everyone for your reference, as follows:
Python re.sub is a standard library of Python regular, with the main function being to match strings to be replaced with regular matches
and replace it with the string you want.
The Re.sub function takes a regular expression-based substitution work
Here is a sample source code
1 #!/usr/bin/env python2 #Encoding:utf-83 ImportRe4URL ='https://113.215.20.136:9011/113.215.6.77/c3pr90ntcya0/youku/6981496DC9913B8321BFE4A4E73/ 0300010e0c51f10d86f80703baf2b1adc67c80-e0f6-4ff8-b570-7dc5603f9f40.flv'5Pattern = Re.compile (r'(? <![ \.\D]) (?: \ D{1,3}\.) {3}\d{1,3} (?! [\.\d])')6 Printpattern.findall (URL)7out = Re.sub (pattern,'127.0.0.1', URL)8 PrintOut
The results of the implementation are as follows:
1 [[email protected] shu]#2 ['113.215.20.136' 113.215.6.77']3 https://127.0.0.1:9011/127.0.0.1/c3pr90ntcya0/ youku/6981496dc9913b8321bfe4a4e73/0300010e0c51f10d86f80703baf2b1adc67c80-e0f6-4ff8-b570-7dc5603f9f40.flv
########### Re.sub Module Detailed
Command: Re.sub (pattern, Repl, String, count=0, flags=0)
The re.sub is used to replace occurrences of strings. If no rule is matched, the original string does not change.
First parameter: rule
Second parameter: replaced string
The third argument: a string
Fourth parameter: Number of replacements. The default is 0, which means that each match is replaced
Python regular substitution string function Re.sub usage example (1)