Converting Confluence markup to a simpler XML format
You are using the wrong tool for the job, as explained here:

https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags

Use XSLT for this job.