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

Find word character in a string with JavaScript RegExp?


To find a 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 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>