I want to remove special characters, exist within the string, but except the first one. I did something like bellow and it works if they are not next to each other.
special char set = '❶❷❸❹❺❻❼❽❾❿➀'
My current code is:
let str = '❶Hi dear how❽ are❺ ❽you❼';
const len = str.length;
for(let i = 0; i < len; i++){
if(i !== 0){
if(str[i] === '❶' || str[i] === '❷' || str[i] === '❸' ||
str[i] === '❹' || str[i] === '❺' || str[i] === '❻' || str[i] === '❼' ||
str[i] === '❽' || str[i] === '❾' || str[i] === '❿' || str[i] === '➀'){
str = str.replace(str[i], '');
}
}
}
console.log('output: ', str);
The above code works well, but if I change str like below then will not work:
let str = '❶Hi dear how❽ are❺❼ ❽❽you❼';
Expected output:
❶Hi dear how are you
Would be better if could be solve this with regex
if it can be faster
than my solutions