我的xml:
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
我需要一个正则表达式来提取“这个周末不要忘记我!”在标记中以及使用正则表达式在python中存在标记。
我编写了一段代码,但我无法弄清楚正则表达式。
答案 0 :(得分:1)
基本解决方案:
import re
data = """
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>"""
found = re.findall('<body>(.*)</body>', data)
if found:
for x in found:
print(x)
>> Don't forget me this weekend!