RegExp.prototype.ignoreCase

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

The ignoreCase accessor property of RegExp instances returns whether or not the i flag is used with this regular expression.

Try it

const regex1 = /foo/;
const regex2 = /foo/i;

console.log(regex1.test("Football"));
// Expected output: false

console.log(regex2.ignoreCase);
// Expected output: true

console.log(regex2.test("Football"));
// Expected output: true

Description

RegExp.prototype.ignoreCase has the value true if the i flag was used; otherwise, false. The i flag indicates that case should be ignored while attempting a match in a string. Case-insensitive matching is done by mapping both the expected character set and the matched string to the same casing.

If the regex is Unicode-aware, the case mapping happens through simple case folding specified in CaseFolding.txt. The mapping always maps to a single code point, so it does not map, for example, ß (U+00DF LATIN SMALL LETTER SHARP S) to ss (which is full case folding, not simple case folding). It may however map code points outside the Basic Latin block to code points within it — for example, ſ (U+017F LATIN SMALL LETTER LONG S) case-folds to s (U+0073 LATIN SMALL LETTER S) and K (U+212A KELVIN SIGN) case-folds to k (U+006B LATIN SMALL LETTER K). Therefore, ſ and K can be matched by /[a-z]/ui.

If the regex is Unicode-unaware, case mapping uses the Unicode Default Case Conversion — the same algorithm used in String.prototype.toUpperCase(). This algorithm prevents code points outside the Basic Latin block to be mapped to code points within it, so ſ and K mentioned previously are not matched by /[a-z]/i.

Unicode-aware case folding generally folds to lower case, while Unicode-unaware case folding folds to upper case. These two are not perfect reverse operations, so there are some subtle behavior differences. For example, Ω (U+2126 OHM SIGN) and Ω (U+03A9 GREEK CAPITAL LETTER OMEGA) are both mapped by simple case folding to ω (U+03C9 GREEK SMALL LETTER OMEGA), so "\u2126" is matched by /[\u03c9]/ui and /[\u03a9]/ui; on the other hand, U+2126 is mapped by Default Case Conversion to itself, while the other two both map to U+03A9, so "\u2126" is matched by neither /[\u03c9]/i nor /[\u03a9]/i.

The set accessor of ignoreCase is undefined. You cannot change this property directly.

Examples

Using ignoreCase

js
const regex = /foo/i;

console.log(regex.ignoreCase); // true

Specifications

Specification
ECMAScript® 2027 Language Specification
# sec-get-regexp.prototype.ignorecase

Browser compatibility

desktop mobile server
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Bun
Deno
Node.js
ignoreCase
Chrome – Full support
Chrome 1 (Release date: 2008-12-11)
footnote Full support
Edge – Full support
Edge 12 (Release date: 2015-07-29)
footnote Full support
Firefox – Full support
Firefox 1 (Release date: 2004-11-09)
footnote Full support
Opera – Full support
Opera 5 (Release date: 2000-12-06)
footnote Full support
Safari – Full support
Safari 1 (Release date: 2003-06-23)
footnote Full support
Chrome Android – Full support
Chrome Android 18 (Release date: 2012-06-27)
footnote Full support
Firefox for Android – Full support
Firefox for Android 4 (Release date: 2011-03-29)
footnote Full support
Opera Android – Full support
Opera Android 10.1 (Release date: 2010-11-09)
footnote Full support
Safari on iOS – Full support
Safari on iOS 1 (Release date: 2007-06-29)
footnote Full support
Samsung Internet – Full support
Samsung Internet 1 (Release date: 2013-04-27)
footnote Full support
WebView Android – Full support
WebView Android 4.4 (Release date: 2013-12-09)
footnote Full support
WebView on iOS – Full support
WebView on iOS 1 (Release date: 2007-06-29)
footnote Full support
Bun – Full support
Bun 1 (Release date: 2023-09-08)
footnote Full support
Deno – Full support
Deno 1 (Release date: 2020-05-13)
footnote Full support
Node.js – Full support
Node.js 0.10 (Release date: 2013-03-11)
footnote Full support
Prototype accessor property (ES2015)
Chrome – Full support
Chrome 48 (Release date: 2016-01-20)
footnote Full support
Edge – Full support
Edge 12 (Release date: 2015-07-29)
footnote Full support
Firefox – Full support
Firefox 38 (Release date: 2015-05-12)
footnote Full support
Opera – Full support
Opera 35 (Release date: 2016-02-02)
footnote Full support
Safari – Full support
Safari 1.3 (Release date: 2005-04-15)
footnote Full support
Chrome Android – Full support
Chrome Android 48 (Release date: 2016-01-26)
footnote Full support
Firefox for Android – Full support
Firefox for Android 38 (Release date: 2015-05-12)
footnote Full support
Opera Android – Full support
Opera Android 35 (Release date: 2016-02-04)
footnote Full support
Safari on iOS – Full support
Safari on iOS 1 (Release date: 2007-06-29)
footnote Full support
Samsung Internet – Full support
Samsung Internet 5 (Release date: 2016-12-15)
footnote Full support
WebView Android – Full support
WebView Android 48 (Release date: 2016-01-26)
footnote Full support
WebView on iOS – Full support
WebView on iOS 1 (Release date: 2007-06-29)
footnote Full support
Bun – Full support
Bun 1 (Release date: 2023-09-08)
footnote Full support
Deno – Full support
Deno 1 (Release date: 2020-05-13)
footnote Full support
Node.js – Full support
Node.js 6 (Release date: 2016-04-26)
footnote Full support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

See also