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

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -