Type "help", "copyright", "credits" or "license" for more information. >>> import re >>> p = re.compile('(http|https)?:?\/?\/?([a-z]*\.?[a-z]*\.[a-z]*)\/?(.*)') >>> m = re.search(p,'http://www.nagios.org') >>> m.group(1) 'http' >>> m.group(2) 'www.nagios.org' >>> m.group(3) '' >>> m = re.search(p,'https://www.nagios.org/foo') >>> m.group(1) 'https' >>> m.group(2) 'www.nagios.org' >>> m.group(3) 'foo' >>> m = re.search(p,'nagios.org/foo') >>> m.group(1) >>> m.group(2) 'nagios.org' >>> m.group(3) 'foo' >>>