Dealing with a string === "1$$$2!@!@3!@!@4!@!@5". I want to be able to split it at both $$$ and !@!@ which are custom delimiters that have been passed in. Since I have to be able to take in any custom delimiter I can't simply use a regex that only pulls out the numbers b/c I could deal with a custom delimiter such as [r9r] which I need to split by.
delimiter = delimiter.substring(0, delimiter.length - 1);
console.log(delimiter) // => "$$$|!@!@"
const regex = new RegExp(`(,|\\n|\\${delimiter})`,'g');
const finalStr = str.substring(str.indexOf('\n'), str.length)
console.log(finalStr); // => "1$$$2!@!@3!@!@45"
let arr = finalStr.split(regex).filter(Boolean);
console.log(arr); // => ["1$$$2", "!@!@", "3", "!@!@", "4", "!@!@", "5"], why does '$$$' stay attached to the 1 and 2?
const finalArr = [];
for (let char of arr) {
if (parseInt(char)) {
finalArr.push(char);
}
}
console.log(finalArr) // => ["1$$$2", "3", "4", "5"]
return finalArr;
I want my final array to be: ["1", "2", "3", "4", "5"] but for some reason the '$$$' doesn't get split like the '!@!@' delimiter does. When I used '!!!' instead of '$$$' it worked so I assume its a special character but still couldn't find a way to accept it.