Movatterモバイル変換


[0]ホーム

URL:


MDN Web Docs

RegExp.prototype.ignoreCase

BaselineWidely available

TheignoreCase accessor property ofRegExp instances returns whether or not thei flag is used with this regular expression.

Try it

const regex1 = /foo/;const regex2 = /foo/i;console.log(regex1.test("Football"));// Expected output: falseconsole.log(regex2.ignoreCase);// Expected output: trueconsole.log(regex2.test("Football"));// Expected output: true

Description

RegExp.prototype.ignoreCase has the valuetrue if thei flag was used; otherwise,false. Thei 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 isUnicode-aware, the case mapping happens throughsimple case folding specified inCaseFolding.txt. The mapping always maps to a single code point, so it does not map, for example,ß (U+00DF LATIN SMALL LETTER SHARP S) toss (which isfull case folding, notsimple 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 tos (U+0073 LATIN SMALL LETTER S) and (U+212A KELVIN SIGN) case-folds tok (U+006B LATIN SMALL LETTER K). Therefore,ſ and can be matched by/[a-z]/ui.

If the regex is Unicode-unaware, case mapping uses theUnicode Default Case Conversion — the same algorithm used inString.prototype.toUpperCase(). This algorithm prevents code points outside the Basic Latin block to be mapped to code points within it, soſ and 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 ofignoreCase isundefined. You cannot change this property directly.

Examples

Using ignoreCase

js
const regex = /foo/i;console.log(regex.ignoreCase); // true

Specifications

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

Browser compatibility

See also

Help improve MDN

Learn how to contribute.

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp