How to use python to replace 'http://xyz.example.com' to 'http://example.com' with regular expression
Note: 'xyz' is just a template. it may be '123' or 'abc-123'
How to use python to replace 'http://xyz.example.com' to 'http://example.com' with regular expression
Note: 'xyz' is just a template. it may be '123' or 'abc-123'
This would do it:
import re
input = 'http://xyz.example.com'
output = re.sub(r'(?<=http:\/\/).*?\.', '', input)
print(output)
(?<=http:\/\/)
is a positive look behind for http://
.*?\.
matches everything that isn't a new line token lazily up until the first .