Match a single letter using regex - Javascript RegExp

Javascript examples for RegExp:RegExp Match

Description

Match a single letter using regex

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){/*from  ww w  .j  a va  2  s.  c o m*/
var patt = /h/gi;
var arr = ["hi", "2Hour", "4Hour", "8Hour", "test hi"];
var test = document.getElementById("test");
for (var i = 0; i < arr.length; i++)
{
    if (/h/gi.test(arr[i])) {
        test.innerHTML += " " + arr[i];
    }
}
    }

      </script> 
   </head> 
   <body> 
      <p id="test"></p>  
   </body>
</html>

Related Tutorials