Improving regex for processing custom SVG.

This commit is contained in:
mike12345567 2022-09-30 09:17:38 +01:00
parent cb0610c367
commit 16d5d8289b
1 changed files with 3 additions and 3 deletions

View File

@ -5,13 +5,13 @@
function substituteSize(svg) { function substituteSize(svg) {
if (svg.includes("height=")) { if (svg.includes("height=")) {
svg = svg.replace(/height="\d*"/, `height="${size}"`) svg = svg.replace(/height="[^"]+"/, `height="${size}"`)
} }
if (svg.includes("width=")) { if (svg.includes("width=")) {
svg = svg.replace(/width="\d*"/, `width="${size}"`) svg = svg.replace(/width="[^"]+"/, `width="${size}"`)
} }
if (svg.includes("id=")) { if (svg.includes("id=")) {
const matches = svg.match(/id="(.*)"/g) const matches = svg.match(/id="([^"]+)"/g)
for (let match of matches) { for (let match of matches) {
svg = svg.replace(new RegExp(match, "g"), Helpers.uuid()) svg = svg.replace(new RegExp(match, "g"), Helpers.uuid())
} }