Hello devs, today we're going to remove special characters from a string. Sometimes we need to extract the special characters from any string, and todays tutorial is about that. So, let's see how we can easily remove special characters from any string.
Let's see the below source code:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>Remove Special Chracter from a String</title> </head> <body> </body> <script> myString = "Hi, shouts$%#dev@@@"; newString = myString.replace(/[^\w\s]/gi, ''); console.log(newString); </script> </html>
And it'll produce the below result:
That's it for today. I hope you've enjoyed this tutorial. Thanks for reading. 🙂