I really tried my best but somehow I cannot make it work.
I have the following SVG path data:
var str = "m 0.05291667,1.7345817 h 0.16018 V 0.05291667 H 1.4943367 v 0.56054601 l -0.16015,0.16017899 0.16015,0.16012501 V 1.4943397 H 0.69354668 V 1.2541247 H 1.2540967 V 1.0138577 L 1.0939467,0.90175268 H 0.69354668 v -0.240215 H 1.0939467 l 0.16015,-0.128138 V 0.29313166 H 0.45330668 V 1.7345817 H 1.6544867"
What I want to achieve is to get all values that come after each H
and increase this value by a number (let's say 2
).
The regex I currently have selects all these numbers:
/(?<=H )(.*?)(?= )/g
However, I don't know how I can increase these numbers now using the replace()
function.
This is what I currently have:
var H = str.match(/(?<=H )(.*?)(?= )/g)
for (var j=0; j<H.length; j++) {
str = str.replace(/(?<=H )(.*?)(?= )/g, function (match, i, original) {
nth++;
return (nth == j) ? (parseFloat(H[j]) + 2).toString() : match;
});
}
But it does not give me the desired result.
What can I do?