我想從Python中使用正則表達式找到一個擴展名「COM」。找到一個字符串python正則域擴展正則表達式
>>> import re
>>> str = 'finding exstention from string on http://domain.coms/index/page/2'
>>> pattern = re.compile(r'([^\s.\s\:]+\.[^\.\s\:]*)')
>>>
結果:
domain : 'domain.com' ### notes: not domain.coms
url : 'http://domain.coms/index/page/2'
先生的預期結果是什麼? – aelor
字符串的結果,抱歉,我忘了給它一些信息。 – Tarjo
@Tarjo你的意思是你需要從'url'中提取'domain'? – nu11p01n73R