2014-04-12 4 views
15

re.search의 결과는 <_sre.SRE_Match object at 0x10d6ed4e0>을 반환합니다.이 문자열을 어떻게 변환 할 수 있습니까? 또는 더 읽기 쉬운 형태?SRE_Match 개체를 문자열로 변환

+2

're.search를 :

result = re.search(your_stuff_here) if result: print result.group(0) 
devnull

답변

14

당신은으로 수행해야합니다()`정규식은 문자열과 일치 여부를 알려줍니다

result = re.search(your_stuff_here) 
if result: 
    print result.groups() 
+2

@ sshashank124 실제로 그룹 매개 변수는 일치하는 그룹의 색인이어야합니다. 예. 정규식이 "abc (def)"이고 일치하는 경우 색인 0에 "abcdef"가 있고 색인 1에 "def"가 있습니다. – lucabelluccini

2

당신이 순서대로 모든 그룹을 보려면

.
관련 문제