Computer >> Computer tutorials >  >> Programming >> Javascript

Find non-word character in a string with JavaScript RegExp.


To find a non-word character (a-z, A-Z, 0-9, _) in a string with JavaScript Regular Expression, use the following −

\W

Example

You can try to run the following code to find a non-word character in a string −

<html>
   <head>
      <title>JavaScript Regular Expression</title>
   </head>

   <body>
      <script>
         var myStr = "100% Responsive!";
         var reg = /\W/g;
         var match = myStr.match(reg);
         
         document.write(match);
      </script>
   </body>
</html>