Sometimes, I have to work with not well formed xml (without root). So I take the first node name (In this case “error”) and make up a regex pattern: "</error>$" The problem is it matches true with the following string. (</error> is the end of the line)
<error>0</error>
<roles>
<role rid="12" title="User" description="Hello world"></role>
<role rid="11" title="Admin" description="Hello world2"></role></roles>
After looking at some reference I tried to do so </error>\z and </error>\Z. but it doesn’t work.
Please help me with the solution
P.S. If there are better solution, I’ll be really happy. Target environment is javascript.
If the only thing that makes your XML not well-formed is that it’s missing root, then the fix is simple – just add some root element and then parse that and work with it as normal XML.
You really shouldn’t try to parse XML with regular expressions.