2013-11-01 30 views

回答

1

這實際上取決於你的格式的一致性。

var numParts = str.split('_'); 
numParts[1]++; 
var updated = '_' + numParts[1] + '_' + numParts[2]; 
1

通用的方法來增加一個字符串的第一個數字:

post_num.replace(/\d+/, function(n){return Number(n) + 1}); 
0
post_num.replace(/^_(\d+)_(\d)$/, function(match, value, sufix) 
            { 
             return "_" + (parseInt(value) + 1) + "_" + sufix; 
            }); 

或幾乎相同:

post_num.replace(/^_(\d+)_(\d)$/, function(match, value, sufix) 
            { 
             return "_" + (+value + 1) + "_" + sufix; 
            }); 
相關問題