Python 正则表达式查找所有xml属性值

Python 正则表达式查找所有xml属性值,python,regex,Python,Regex,我试图从一个大的xml文件中提取所有属性值 s = '<some id="Foo" menu="BAAR"></some>' output = re.findall( '="(.*)"' ,s) print output 不管我怎样 ['Foo" menu="BAAR'] 有谁能帮我指出我做错了什么吗?在正则表达式中*是贪婪的,这意味着,它尽可能多地消耗。只需使用非贪婪版本*?: s = '<some id="Foo" menu="BAAR"></s

我试图从一个大的xml文件中提取所有属性值

s = '<some id="Foo" menu="BAAR"></some>'
output = re.findall( '="(.*)"' ,s)
print output
不管我怎样

['Foo" menu="BAAR']

有谁能帮我指出我做错了什么吗?

在正则表达式中
*
是贪婪的,这意味着,它尽可能多地消耗。只需使用非贪婪版本
*?

s = '<some id="Foo" menu="BAAR"></some>'
output = re.findall( '="(.*?)"' ,s)
print output
s=''
输出=re.findall('=“(.*)”,s)
打印输出

不要使用正则表达式解析XML!您可能会发现使用xpath对此很有用
s = '<some id="Foo" menu="BAAR"></some>'
output = re.findall( '="(.*?)"' ,s)
print output