Python 正则表达式匹配字符串中的http链接方法 利用Python正则表达式匹配字符串中的http链接。主要难点是用正则表示出http 链接的模式。 import re pattern = 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'] 以上这篇Python 正则表达式匹配字符串中的http链接方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持中文源码网。