JavaScript: Combining Square Brackets and Case

JavaScript regular expression square brackets and case sensitivity can be combined:

//Will return false because the ‘i’ flag is not set and ‘J’ is upper case
var IsFound = /[joey]/.test(”J”);
alert(IsFound);

//Will return true because the ‘i’ flag is set and ‘J’ matches one of the characters in the brackets
var IsFound = /[joey]/.test(”J”);
alert(IsFound);

Leave a Reply