2014-04-06 4 views
0

작업 내가파이썬 정규 표현식

blahblah'url=:'http://link.com/=tag/blahblah'url=:'http://link2.com/=tag' 

내 정규 표현식의 모습을 .txt 파일에있는 모든 링크를 찾을 정규식을 사용하고 :

links = re.findall(r"url=:'http://.+?=tag", source) 

결과를 :

url=:'http://link.com/=tag/, url=:'http://link2.com/=tag' 

답변

2

주위에 캡처 그룹을 사용하십시오. 원하는 패턴은 반환

links = re.findall(r"(url=:'http://.+?=tag)", source) 

데모 :

>>> import re 
>>> source = "blahblah'url=:'http://link.com/=tag/blahblah'url=:'http://link2.com/=tag'" 
>>> re.findall(r"(url=:'http://.+?=tag)", source) 
["url=:'http://link.com/=tag", "url=:'http://link2.com/=tag"] 
+0

@devnull : 수정 주셔서 감사합니다. –