a = "http://127.0.0.1:80/" #a = "127.0.0.1:80/" ok too a.split('//')[-1].split('/')[0].rsplit(':',1) ['127.0.0.1', '80']