in reply to Regular expression question

choroba is right (++). For something as complex as an <svg> element and its subtree, using regex will just be a rabbit hole. There are plenty of proper parsers around, so choose one of those instead. But do have a read of the literature, eg: Parsing HTML The Cthulhu Way for an appreciation of doing things properly and of when you don't have to.