Javascript正则表达式,在方括号之间找到文本。

时间:2022-08-28 21:43:58

Find:

发现:

ellora[sidebar-1]

and replace only the number, specially finding text in between square brackets (both opening and closing) and replace. Using replace()

并且只替换数字,特别是在方括号(打开和关闭)之间找到文本并替换。使用替代()

method.result

should be like this

应该是这样

ellora[sidebar-2], ellora[sidebar-3], ...

1 个解决方案

#1


3  

Something like this:

是这样的:

s = s.replace(/(\w+\[\w+[_-])(\d+)(\])/g, function(str, p1, p2, p3) {
    return p1 + (parseInt(p2) + 1) + p3;
});

#1


3  

Something like this:

是这样的:

s = s.replace(/(\w+\[\w+[_-])(\d+)(\])/g, function(str, p1, p2, p3) {
    return p1 + (parseInt(p2) + 1) + p3;
});