Remove Special Characters from a JavaScript String using Regular Expression



To remove all special characters from a JavaScript string, you can try to run the following code −

Example

<html>
   <head>
      <script>
         var str = "@!Welcome to our website$$";
         document.write(str);
         
         // Removing Special Characters
         document.write("<br>"+str.replace(/[^\w\s]/gi, ''));
      </script>
   </head>
   
   <body>
   </body>
</html>
Updated on: 2020-06-23T05:34:43+05:30

649 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements