如何递减字符串中的数字?现在我得到了这个:
var existingId = "test 10 test";
let newId = existingId .replace(/\d+/g, function(match, number) {
return parseInt(number)-1;
});
数字并不总是在同一个地方。我无法将数字存储在变量中。
但是我的正则表达式不正确。
最佳答案
你差不多明白了
var existingId = "test 10 test";
let newId = existingId.replace(/\d+/g, function(match) {
return parseInt(match) - 1;
});
关于字符串中的Javascript递减数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46543417/