import repattern = re.compile(r'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*/(/),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+') # 匹配模式string = 'Its after 12 noon, do you know where your rooftops are? http://tinyurl.com/NYCRooftops 'url = re.findall(pattern,string)print url>>['http://tinyurl.com/NYCRooftops']