One of the most common operations that programmers use on strings is to check whether a string contains some other string.
In this post you will see how to check string contains whether other string with insensitive.
Way 1: Check string with match() method
1 2 3 4 5 6 7 8 | var str="WELCOME to CODE 4 Example"; var regex = /welcome/i; var found = str.match(regex); console.log(found[0]); // WELCOME |
Way 2: Check string by converting to uppercase or lowercase
1 2 3 4 5 6 7 8 9 10 11 | var str="WELCOME to CODE 4 Example"; var search="welcome"; var search2="Coding"; var state= str.toLowerCase().includes(search.toLowerCase()); var state2= str.toLowerCase().includes(search.toLowerCase()); console.log(state);//true console.log(state2);//false |