const newSvg = oldSvg + svg.trim()
.replace(/(^<\?xml[^>]*>)|/g, '')
.trim()
.replace(/(^<svg[^>]*>)|(<\/svg>$)/g, '');
console.log(newSvg);
<svg></svg><path d=""></path>
<svg>
<path d=""></path>
</svg>
const oldSvg = data.editor.svg;
const newSvg = svg.trim()
.replace(/(^<\?xml[^>]*>)|/g, '')
.trim()
.replace(/(^<svg[^>]*>)|(<\/svg>$)/g, '');
const position = oldSvg.length - 6;
const svgResult = [oldSvg.slice(0, position), newSvg, oldSvg.slice(position)].join('');