I have a sentence where in place of {#val#}, there could be any value within the limit of 5. And also I need to remove special characters except few in a sentence given below. I'm trying to do like below.
var separators = ["#val#", "#VAL#", "#vaL#", "#vAl#", "#Val#"];
let sentence = "Hi {#VAL#}, Thank you {#val#}{#val#} for &visting us!";
separators.forEach((str) => {
regexString = regexString.replace(new RegExp(`{${str}}`, "g"), ".{0,5}"); //Replacing val with .{0,5}
});
Im trying to use ternary operator in order to only replace special characters except .{0,5}, but this seems to be not working.
regexString = regexString.replace(/([&\/\\,+()$~%'":?<>_;||`~!^@=+{}\[\]\-])/g,(x,z) => {
x == ".{0,5}" || x == "\s" ? "" :".{0,5}"
})
Kindly help me on this.