考虑这个:正则表达式来提取标记及其内容
input = """Yesterday<person>Peter</person>drove to<location>New York</location>"""
一个如何使用正则表达式模式来提取:
person: Peter
location: New York
这个效果很好,但我不想硬编码的标签,他们可以改变:
print re.findall("<person>(.*?)</person>", input)
print re.findall("<location>(.*?)</location>", input)
你越来越接近危险的http://stackoverflow.com/a/1732454/3001761 – jonrsharpe
@DevEx请参阅修改的答案 – PyNEwbie