JavaScript > Regular Expressions Modifiers

ignoreCase Property in JavaScript

How to check whether "i" modifier is set or not in JavaScript?


ignoreCase

ignoreCase is an property in JavaScript Regular expressions, which is used to find whether "i" modifier is set or not for the case-insensitive search. 

It is an boolean type property, If "i" modifier is set for the search, the ignoreCase property returns "true", other wise it returns "false".

ignoreCase property with "i" modifier.

<p>Click the below button to find whether "i" modifier is set or not.</p>
<input type="button" value="Search" onclick="testFunction()"/>
<p id="myId"></p>

<script>
    function testFunction() {
        var a = "TechFunda Provides lot technology "
        var b = /lot/i;
        var r = b.ignoreCase;
        document.getElementById("myId").innerHTML = r;
    }
</script>

In the above code snippet we used "i" modifier for the case-insensitive search. We are checking whether "i" modifier is set or not by using ignoreCase property.

Onclick button finds whether "i" modifier is set or not and return the output.

OUTPUT

ignoreCase property without "i" modifier.

<p>Click the below button to find whether "i" modifier is set or not.</p>
<input type="button" value="Search" onclick="testFunction()"/>
<p id="myId"></p>

<script>
    function testFunction() {
        var a = "TechFunda Provides lot technology "
        var b = /lot/g;
        var r = b.ignoreCase;
        document.getElementById("myId").innerHTML = r;
    }
</script>

ignoreCase property without "i" modifier

In the above code snippet we used "g" modifier for the global search.

OUTPUT

 Views: 5866 | Post Order: 153



Write for us






Hosting Recommendations