Hi Everyone,

Do you know how i can get the values using Regular Expression between the opening and closing tags of xml files? I need to process xml files using python and i just need to get the values between tags.
For example:

<name value>my name is </name value>

i just need to get the value my name is using regular expression.
can someone help me with this?

thanks!

Recommended Answers

All 4 Replies

import re

target = '<name value>my name is</name value>'
mobj = re.search('<.*>(.*)</.*>', target)
print mobj.groups()[0]

hi cghtkh!

thanks for your answer!

import re

target = '<name value>my name is</name value>'
mobj = re.search('<.*>(.*)</.*>', target)
print mobj.groups()[0]

Quote from stack overflow:

"asking regexes to parse arbitrary HTML is like asking Paris Hilton to write an operating system"

so it may not be the right tool... (Not meaning that I could write an OS either).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.