Reputation: 1036
I have this XML:
<[Results]>
<[Data]>
<[div]>THIS IS HTML! <[/div]>
<[/Data]>
<[/Results]>
What is the regular expression to get <[div]>THIS IS HTML!<[/div]>
?
Upvotes: 0
Views: 113
Reputation: 175088
Try this:
<\[div\]>.+?<\[\/div\]>
Will match anything inside the div tags.
Though I am complied to tell you that that regex is NOT perfect. If you want to parse XML, you should use an XML parser.
Do read this post on the subject thoroughly.
Upvotes: 0
Reputation: 69964
If you can convert this to actual XML, instead of a string, you could use the getElementsByTagName method to find all div tags and the innerHTML(?) property (or innerText/textContent depending on what you want)
Upvotes: 0
Reputation: 489
http://www.codinghorror.com/blog/2009/11/parsing-html-the-cthulhu-way.html
Do not parse XML with regexes. Do not.
Upvotes: 2
Reputation: 2755
You should avoid catch <´s in the body if you have 2 or more DIVs. Try this:
<[div]>[^<]<[/div]>
Upvotes: -1