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

HTMLJavascriptProgramming Scripts

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>
raja
Published on 26-Feb-2018 06:27:09
Advertisements