1

What regular expression can I use that sums or subtracts a part of a string?

For instance:I can count to 10! and it replaces as I can count to 9!

jondiaz
  • 160
  • 8

1 Answers1

0

You can use a regex function to change the matched value. Something like this should work:

var str = "I can count to 10!";

str = str.replace(/[0-9]+[0-9]/, function (match, capture) { return match-1;});
console.log(str)

You can see it working here: https://jsfiddle.net/rmtuk3j1/

Adam Konieska
  • 2,805
  • 3
  • 14
  • 27