Home > Article > Backend Development > Python regular replacement string function re.sub usage example
The example in this article describes the usage of Python regular replacement string function re.sub. Share it with everyone for your reference. The details are as follows:
python re.sub belongs to the python regular standard library. Its main function is to match the string to be replaced with regular expression
and then replace it. How to create the string you want
re.sub function performs replacement work based on regular expressions
The following is a sample source code
#!/usr/bin/env python #encoding: utf-8 import re url = 'https://113.215.20.136:9011/113.215.6.77/c3pr90ntcya0/youku/6981496DC9913B8321BFE4A4E73/0300010E0C51F10D86F80703BAF2B1ADC67C80-E0F6-4FF8-B570-7DC5603F9F40.flv' pattern = 'http://(.*?):9011/' out = re.sub(pattern, 'http://127.0.0.1:9091/', url) print out
The running effect diagram is as follows:
For more Python regular replacement string function re.sub usage examples and related articles, please pay attention to the PHP Chinese website!