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
My solution is to get the splitters then save them into an array and rejoin:
function splitAndRejoin(){
const str = "Hello+Beautiful#World";
const splited = str.split(/[\+#]/);
var spliterCharacter = [];
for(var i = 0; i < str.length; i++){
if(str[i] == "+" || str[i] == "#"){
spliterCharacter.push(str[i]);
}
}
var rejoin = "";
for (i = 0; i <= spliterCharacter.length; i++) {
if(i< spliterCharacter.length)
rejoin += splited[i] + spliterCharacter[i];
else
rejoin += splited[i];
}
console.log(splited);
console.log(spliterCharacter);
console.log(rejoin); // Result
}