What is ignorecase?

The ignoreCase property in Javascript specifies if the Regular expression will perform case-insensitive matching when comparing two strings.

The property returns True or False based on the value of the i attribute of RegExpRegular Expression objects.

Code

If the i attribute is set to True, the regular expression will infer “ABC” and “aBc” as the same strings.

const r1 = new RegExp('foo');
const r2 = new RegExp('bar', 'i');
console.log(r1.test('Football'));
// Returns false since ignoreCase property is not set.
// Hence it does not detect foo in Football
console.log(r2.ignoreCase);
// Returns true since ignoreCase property is set to True
console.log(r2.test('Barricade'));
// Returns true since it detects bar in Barricade by
// ignoring the case

Free Resources