-1

I'm trying to extract all attribute values from a large xml file

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

I'm expecting out put

['Foo','BAAR'] 

However I'm getting

['Foo" menu="BAAR']

Can anyone please help me pointing out what I'm doing wrong ?

Dev.K.
  • 2,428
  • 5
  • 35
  • 49

1 Answers1

-1

In regular expression * is greedy, that means, it takes as much as it can. Just use the non-greedy version *?:

s = '<some id="Foo" menu="BAAR"></some>'
output = re.findall( '="(.*?)"' ,s)
print output
Daniel
  • 42,087
  • 4
  • 55
  • 81