利用Python正則表達式匹配字符串中的http鏈接。主要難點是用正則表示出http 鏈接的模式。
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']
以上這篇Python 正則表達式匹配字符串中的http鏈接方法就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持武林站長站。
新聞熱點
疑難解答