I have a string that need to be split with a regular expression for applying some modifications.
eg:
const str = \"Hello+Beautiful#World\";
const spl
When you place a pattern inside a capturing group, split
will return the matched delimiters as even array items. So, all you need to do is modify the odd items:
var counter=1;
var str = "Hello+Beautiful#World";
console.log(
str.split(/([+#])/).map(function(el, index){
return el + (index % 2 === 0 ? (counter++ + "").padStart(3, '0') : '');
}).join("")
);