replace(/(.*)\/(.*)/, "newPath/$2"); Main image let newStr = str.replace(/\-(\d+)/g, (match, p1) => { return parseInt(p1) + 1; });