I guess it is a matter of parsing svg. Trying to hack around with regex is asking for trouble indeed.