
Untitled
By: a guest on
May 8th, 2012 | syntax:
None | size: 0.67 KB | hits: 8 | expires: Never
How to Perform Operations on Regex Backreference Matches in Javascript?
var string = "This is a string with numbers 1 2 3 4 5 6 7 8 9 10";
var desiredResult = "This is a string with numbers 2 3 4 5 6 7 8 9 10 11";
string.gsub(/(d+)/) { "#{$1.to_i + 1}"}
var x = "This is x1, x2, x3.";
var y = x.replace(/x(d+)/g, function(m, g1) {
return "y" + (Number(g1)+1);
});
y; // => "This is y2, y3, y4."
var string = "This is a string with Numbers 1 2 3 4 5 6 7 8 9 10";
var desiredResult = "This is a string with Numbers 2 3 4 5 6 7 8 9 10 11";
var actualResult = string.replace(/([0-9]+)/g, function() {
return parseInt(arguments[1])+1
});
console.log(actualResult)