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]>
?
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]>
?
http://www.codinghorror.com/blog/2009/11/parsing-html-the-cthulhu-way.html
Do not parse XML with regexes. Do not.
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.
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)
You should avoid catch <´s in the body if you have 2 or more DIVs. Try this:
<[div]>[^<]<[/div]>
Content here...
<[/div]>`. I guess it should match that too... – Arjan Aug 12 '11 at 17:12