I am trying to replace all the special characters even space but not numbers with -
but if there are multiple special characters like [///
then it should only replace -
I have added my expected output in snippet
const string= "![astronaut-lost-in-space-rk](//images.ctfassets.net/c8qz6f7npv42/fJd9r4N1eriItv5XNp0uv/4b46d52459ea20684c653a1c200b5aa1/astronaut-lost-in-space-rk.jpg)";
console.log(string.replace(/[^a-zA-Z ]/g, "-"));
console.log("Expected Output")
console.log("-astronaut-lost-in-space-rk-images-ctfassets-net-c8qz6f7npv42-fjd9r4n1eriitv5xnp0uv-4b46d52459ea20684c653a1c200b5aa1-astronaut-lost-in-space-rk-jpg-")
In snippet you can see I have 4 special characters present at like this ])\
and it getting replace by -
by 4 times ----
I want to replace special characters but if it present more then 1 then it should replace every special character but show only one -