Just to show one way,it's not normal to parse all input when have markup input.
Think of a web-site of XML doc that can have 100/1000 of tags,then want to narrow it down to find parse info needed.
There had been no problem to solve this specific task with with regex,
it just that when see markup there is a better way which is using a parser.
Also as info Regex is supported for use inside both BeautifulSoup and lxml.
Eg:
I have like to that post bye @bobince many times over the years.
Think of a web-site of XML doc that can have 100/1000 of tags,then want to narrow it down to find parse info needed.
There had been no problem to solve this specific task with with regex,
it just that when see markup there is a better way which is using a parser.
Also as info Regex is supported for use inside both BeautifulSoup and lxml.
Eg:
soup.find_all(re.compile("^b"))
.//a[re:test(@id, "^hypProduct_[0-9]+$")]
from bs4 import BeautifulSoup data = '''\ <Color>blue</Color> <Code>1</Code> <Color>red</Color > <Code>2</Code>''' soup = BeautifulSoup(data, 'lxml') for item in soup.find_all(['color', 'code']): print(f'{item.name.capitalize()}:{item.text}')
Output:Color:blue
Code:1
Color:red
Code:2
ichabod801 Wrote:I think maybe that's overstating it a little bit.Sure it is,but it's one the best and funny post about this topic.
I have like to that post bye @bobince many times over the years.