【发布时间】:2014-05-05 02:17:19
【问题描述】:
如何使用正则表达式或 beautifulsoup、lxml 等工具包解析这样的句子:
input = """Yesterday<person>Peter Smith</person>drove to<location>New York</location>"""
进入这个:
Yesterday
<person>Peter Smith</person>
drove
to
<location>New York</location>
我不能使用re.findall("<person>(.*?)</person>", input),因为标签不同。
【问题讨论】:
-
您可以使用竖线 (|) 在正则表达式中查找多重模式,例如:(
(.*?) |(.)* ) -
嵌套标签呢?如果你有它们应该是什么输出?
标签: python regex xml-parsing beautifulsoup lxml