다른 경기 전에 경기의 발생 :정규식/파이썬 : N -이 같은 XML 파일의 구조를 가지고
<word id="15" pos="SS">
<token>infarto</token>
<lemmas>infarto</lemmas>
</word>
<word id="16" pos="AS">
<token>miocardico</token>
<lemmas>miocardico</lemmas>
</word>
<word id="17" pos="AS" annotated="head">
<token>acuto</token>
<lemmas>acuto</lemmas>
</word>
<word id="18" pos="E">
<token>in</token>
<lemmas>in</lemmas>
</word>
<word id="19" pos="SS">
<token>corso</token>
<lemmas>corso</lemmas>
</word>
나는, "POS"와 "토큰에 대한 값을 받고 할 노력하고있어 "라는 단어가 17 번 단어 (annotated ="head "하나)라는 단어를 둘러싼 단어를 가리 킵니다.
이
은 모든 문제는 단어 뒤에오고 일치이다 (17)(pos=")(.+)(")(\s\S+?)("head")([\s\S]+?)(>)(\w+?)(<+)([\S\s]+?)(pos=")(.+)(")([\s\S]+?) (token>)(.+)(<)([\s\S]+?)
이 내가 원하는 모든 정보를 저를 얻고 I 확장 할 경우 난 그냥에
(pos=")(.+)(")([\s\S]+?)(token>)(.+)(<)([\s\S]+?)
을 추가 할 수 있습니다 종료. 그것은 예쁘지 않지만 작동합니다. 나는 다른 방향으로 가고 싶어 갈 때
는 지금, 나는 절대적으로 그것을 단어 16 ("주석 머리"앞에있는 첫 번째)의 정보와 일치하는 대신
(pos=")(.+)(")([\s\S]+?)(token>)(.+)(<)([\s\S]+?)(pos=")(.+)(")(\s\S+?)("head")
을 난처한 상황에 빠진거야 앞에 오는 모든 정보 (단어 15, 단어 14, 단어 13 등)와 일치합니다.
무엇이 누락 되었습니까?
P. XML 파서를 사용하는 것은 슬프게도 옵션이 아닙니다.
regexes가 아닌이 유형의 작업에 XML 라이브러리를 사용해야합니다. – armandino
당신은 html이나 xml을위한 정규 표현식을 사용해서는 안됩니다. http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags –
http://stackoverflow.com/questions/6751105/why-its-not-possible- 사용법 -regex-to-parse-html-xml-a-formal-explanation-in-la –