我想在URL字符串上使用python正則表達式。Python的正則表達式 - 區別搜索和查找所有
id= 'edu.vt.lib.scholar:http/ejournals/VALib/v48_n4/newsome.html'
>>> re.search('news|ejournals|theses',id).group()
'ejournals'
>>> re.findall('news|ejournals|theses',id)
['ejournals', 'news']
根據在http://docs.python.org/2/library/re.html#finding-all-adverbs的文檔,它說,搜索()相匹配的第一個,找到所有的字符串中的所有可能的人相匹配。
我想知道爲什麼'news'沒有被搜索捕獲,即使它是在模式中聲明的第一個。
我使用了錯誤的模式嗎?我想搜索這些關鍵字是否出現在字符串中。
謝謝。我的壞,我沒有想到這一點。 – kich 2013-02-26 22:00:52