How to perform Case Insensitive matching with JavaScript RegExp?

HTMLJavascriptProgramming Scripts

To perform case-insensitive matching, use the I modifier available in JavaScript Regular Expression.

Example

You can try to run the following code for case-insensitive matching −

<html>
   <head>
      <title>JavaScript Regular Expression</title>
   </head>
   <body>
      <script>
         var myStr = "Welcome to the website!";
         var reg = /welcome/i;
         var match = myStr.match(reg);
         
         document.write(match);
      </script>
   </body>
</html>
raja
Published on 26-Feb-2018 10:50:36
Advertisements