Do you need something more than lower?
var num=2 // parse this from drafts [2] num++; var newstr=str.replace(/\[(.+?)\]/g, "["+num+"]")
Or can the brackets change to <> {} at the input?
You can also specify a function instead of a replacement string.
var str = "Drafts [2]"; function replacer(match, p1, p2, p3, offset, string) { return p1 + (1+parseInt(p2)) + p3; } var newstr=str.replace(/([\[(])(.+?)([\])])/g, replacer); alert(newstr);
source share