i want to replace all semicolon (;) with plus (+) sign except the last semicolon.
ex -
i have something like this -
i want to get result like this -
so far i tried
replace(/;/g, ' + ')
but this replace every semicolons.
the size of a line/word is dynamic i.e. changes from line to line.
With a look ahead
console.log("A;".replace(/;(?=[^;]*;)/g,' + '));
console.log("A;B;".replace(/;(?=[^;]*;)/g,' + '));
console.log("A;B;C;".replace(/;(?=[^;]*;)/g,' + '));
console.log("A;B;C;D;".replace(/;(?=[^;]*;)/g,' + '));