Javascript regex, replacing numbers with manipulated number -
i have following string:
"4/7/12"
and replace each number formula: (25 - x) 'x' number string.
for example: "4/7/12" translated into: "21/18/13"
how can using 'replace()' , regex ??
var player_move = "5/7/9"; var translated_pm = player_move.replace(/\/\*?/, 25 - /$1/);
thank you!
try this
var translated_pm = player_move.replace(/\d+/g, function (x){return 25 - parseint(x)});
Comments
Post a Comment