Using the ElementTree to parse XML, I am getting tags that look like this: "{namespace}tag". I need an easy way to strip off the namespace.
>>> import re
>>> str = "{blat}tag"
>>> re.findall(r'{.*}', str)
['{blat}']
>>> str += "{goo}asdf{boing}blat"
>>> re.findall(r'{.*}', str)
['{blat}tag{goo}asdf{boing}']
>>> re.findall(r'{.*?}', str)
['{blat}', '{goo}', '{boing}']
>>> re.findall(r'{.*?}', str)[0]
'{blat}'
>>> goo = re.findall(r'{.*?}', str)[0]
>>> goo
'{blat}'
>>> goo[1:len(goo)-1]
'blat'
I'm sure the { and } could be stripped off with the regular expression. I still have to play with it.
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment