JavaScript | RegExp ignoreCase Property

The RegExp ignoreCase property in JavaScript is used to specify whether the “i” modifier is set or not. If the “i” modifier is set than this property returns true otherwise returns false.

Syntax:

RegexObj.ignoreCase

Return Value: It returns true if i modifier is set, else false.



Example 1: This example checks if the regular expression contains i Modifier or not.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
    <head>
        <title>
            RegExp ignoreCase Property
        </title>
    </head>
      
    <body style="text-align:center">
          
        <h1 style="color:green">
            GeeksforGeeks
        </h1>
          
        <h2>ignoreCase Property</h2>
          
        <button onclick="geek()">
            Click it!
        </button>
  
        <script>
            function geek() {
                var regex = new RegExp('foo', 'i');
                alert(regex.ignoreCase);
            }
        </script>
    </body>
</html>                    

chevron_right


Output:
Before clicking the button:
ignoreCase
After clicking the button:
ignoreCase

Example 2: This example checks the regular expression contains i Modifier or not.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html> 
<html
  
<head
    <title
        JavaScript ignoreCase Property 
    </title
</head
  
<body style="text-align:center"
      
    <h1 style="color:green"
        GeeksforGeeks 
    </h1
      
    <h2
        ignoreCase Property 
    </h2
      
    <button onclick="geek()"
        Click it! 
    </button
  
    <script
        function geek() { 
            var regex = /[a-d]/; 
            var str = 
                "GeeksforGeeks\n"+ 
                "is the computer\n"+ 
                "science portal for geeks."; 
              
            if (regex.ignoreCase) { 
                alert("i Modifier is present"); 
            } else { 
                alert("i Modifier is absent."); 
            
        
    </script
</body
  
</html>                    

chevron_right


Output:
Before clicking the button:
ignoreCase
After clicking the button:
ignoreCase

Supported Browsers: The browsers supported by JavaScript ignoreCase property are listed below:

  • Google Chrome
  • Internet Explorer
  • Mozilla Firefox
  • Apple Safari
  • Opera


My Personal Notes arrow_drop_up


If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.