 <p>Quoting from <a href="http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454">RegEx match open tags except XHTML self-contained tags</a> :</p> <blockquote> <p>You can't parse [X]HTML with regex. Because HTML can't be parsed by regex. Regex is not a tool that can be used to correctly parse HTML. [...] Regular expressions are a tool that is insufficiently sophisticated to understand the constructs employed by HTML. HTML is not a regular language and hence cannot be parsed by regular expressions. Regex queries are not equipped to break down HTML into its meaningful parts.</p> </blockquote> <p>The conclusion I case was the same as the author:</p> <blockquote> <p>Have you tried using an[sic] XML parser instead?</p> </blockquote> <p>Which is what you can do!</p> <p>Try this:</p> <p><div class="snippet" data-lang="js" data-hide="false"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><code>var fragment = document.createDocumentFragment(); var elem = document.createElement('div'); fragment.appendChild(elem); elem.innerHTML = '&lt;svg viewBox="0 0 120 120" version="1.1" xmlns="http://www.w3.org/2000/svg"&gt;&lt;circle cx="60" cy="60" r="50"/&gt;&lt;/svg&gt;'; alert(elem.getElementsByTagName('circle')[0].getAttribute('cx'));</code></pre> </div> </div> </p> <p>It should alert <code>60</code>.</p> <p>Javascript provides all the tools to mess with this. Just pretend that the string is HTML and you should be fine!</p> <hr> <p><strong>Note</strong>: that code is just an example! Addapting it to work properly is easily done in 5 minutes or less.</p>