파이썬 정규표현식 질문입니다. 특정 문자열만 추출하려고 합니다.

posinate의 이미지

다음과 같은 문자열에서 "폰트 특수효과부분을 제거한" 나머지 문자열만 추출하려고 합니다.

특수효과를 주는 부분은 '&lt'; 문자열 '&gt'; <- 이와 같이 구성되어 있습니다. (즉 저는 '&lt'; ~ '&gt'; 까지를 모두 제거하려고 합니다)

'&lt';img src="/img/koz/kzcolor.gif" alt="Image from coursera museum: Csw as an Artist" width="138" height="130" align="right" p'&gt'; The Gallem '&lt';bArts/b'&gt'; category contains English contents about art

1. '&lt';img src="/img/koz/kzcolor.gif" alt="Image from Mozilla museum: Mozilla as an Artist" width="128" height="120" align="right" p'&gt';
2. '&lt';bArts/b'&gt';

이렇게 두 문자열을 제거하고 The Gallem category contains English contents about art <= 이 녀석만 남기려고 합니다.

해결했습니다.

import re

des = '<go to where we are!> The contents I need is < shit the fuck this line> is it'

def purify (description) :
tmp = description

while(tmp.find('<') != -1):
tmp2 = tmp
idx1 = tmp2.find('<')
idx2 = tmp2.find('>')
tmp = tmp[:idx1] + tmp[idx2+4 : ]
print(tmp)

purify(des)

이와 같은 코드로 해결했습니다~!

kikiki0611의 이미지

비슷한 아티클이 있습니다.
읽어보셔요.

https://blog.ostermiller.org/find-comment

keyword : find block comment using regex