Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我使用.replace(/([0-9])/, '$1' + 1);for 字符串将数字替换为数字 + 1,但不起作用,我知道它是字符串和整数,但是如何在 JS 中这样做?
.replace(/([0-9])/, '$1' + 1);
您不能在替换字符串中执行数学运算。
相反,您需要传递一个回调函数:
.replace(/0-9/, function(m) { return parseInt(m, 10) + 1; })