there is a string and RegExp:
var str = "a1c a23c a456c 123";
var re = /a(\d*)c/g;
I want to match all number between a and c, and replace it to b, the result I would like is:
"abc abc abc 123"
how to do it?
Try this
var str = "a1c a23c a456c 123";
var re = /(a)(\d*)(c)/g;
console.log(str.replace(re, '$1b$3'));
EDIT:
If ac should not become abc, then regex should be /(a)(\d+)(c)/g
Try this:
var str = "a1c a23c a456c 123";
var newStr = str.replace(/\ba\d+c\b/g, "abc");
console.log(newStr);
/\ba\d+c\b/g, 'abc'.
"ac"with no number - is that deliberate?