-2

I need to delete the following characters from a url ":" "." "\" "/" how can i do this in javascript?

original: https://www.sito.it/ricette-cat.html
convert: https-www-sito-it-ricette-cat-html

thanks

Jon Clements
  • 138,671
  • 33
  • 247
  • 280
carver14
  • 41
  • 9
  • Your question asks about deleting chars but the expected result is for them to have been replaced with dashes, which is it? This is also covered in a lot of SO questions such as https://stackoverflow.com/questions/1144783/how-to-replace-all-occurrences-of-a-string. – Karl-Johan Sjögren May 17 '20 at 13:22

1 Answers1

1

var str = 'https://www.sito.it/ricette-cat.html'
console.log(str.replace(/[^\w]+/ig,'-'))
Rush W.
  • 1,321
  • 2
  • 11
  • 19
  • thank you very much! Thanks so much! I'm a beginner with programming, what do these symbols do ? / [^ \ w] + / ig? – carver14 May 17 '20 at 13:39
  • `^ -> is negation` , `\w (word character) matches any single letter, number or underscore`, and enclosing them within [] with + match one or more characters. If you found that useful, make sure to upvote. – Rush W. May 18 '20 at 12:17