You can use BeautifulSoup
for this HTML parsing.
input = """"<person>John</person>went to<location>London</location>"""
soup = BeautifulSoup(input)
print soup.findAll("person")[0].renderContents()
print soup.findAll("location")[0].renderContents()
Also, it's not a good practice to use str
as a variable name in python as str()
means a different thing in python.
By the way, the regex can be:
import re
print re.findall("<person>(.*?)</person>", input, re.DOTALL)
print re.findall("<location>(.*?)</location>", input, re.DOTALL)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…