I have a string 2A some text 2B 2C some text 2D and I want to swap 2 with its' next character.
The result will be A2 some text B2 C2 some text D2.
How can I achieve it?
I tried as below but it doesn't work.
const str = '2A some text 2B 2C some text 2D';
const strArray = str.split("");
const result = str.replace(/2/gm,(match,index)=>{
return strArray[index+1]+match;
})
document.write(result)