RegExp.prototype.ignoreCase

RegExp 实例的 ignoreCase 访问器属性返回此正则表达式是否使用 i 标志。

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

Try it

描述

¥Description

如果使用了 i 标志,则 RegExp.prototype.ignoreCase 的值为 true;否则,falsei 标志指示尝试在字符串中进行匹配时应忽略大小写。不区分大小写的匹配是通过将预期字符集和匹配字符串映射到相同的大小写来完成的。

¥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.

如果正则表达式为 Unicode 感知,则大小写映射通过 CaseFolding.txt 中指定的简单大小写折叠进行。该映射始终映射到单个代码点,因此它不会将 ß (U+00DF LATIN SMALL LETTER SHARP S) 映射到 ss(这是完整大小写折叠,而不是简单大小写折叠)。但是,它可能会将基本拉丁语块外部的代码点映射到其中的代码点 — 例如,ſ (U+017F LATIN SMALL LETTER LONG S) 大小写折叠到 s (U+0073 LATIN SMALL LETTER S) 和 (U+ 212A KELVIN SIGN)表壳折叠至 k(U+006B 拉丁文小写字母 K)。因此,ſ 可以通过 /[a-z]/ui 来匹配。

¥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 (U+212A KELVIN SIGN) case-folds to k (U+006B LATIN SMALL LETTER K). Therefore, ſ and can be matched by /[a-z]/ui.

如果正则表达式不支持 Unicode,则大小写映射将使用 Unicode 默认大小写转换 — 与 String.prototype.toUpperCase() 中使用的算法相同。例如, (U+2126 OHM SIGN) 和 Ω (U+03A9 希腊大写字母 OMEGA) 均通过默认大小写转换映射到自身,但通过简单大小写折叠映射到 ω (U+03C9 希腊小写字母 OMEGA),因此 "ω"/[\u2126]/ui/[\u03a9]/ui 匹配,但与 /[\u2126]/i/[\u03a9]/i 不匹配。该算法防止基本拉丁语块外部的码点映射到其中的码点,因此前面提到的 ſ/[a-z]/i 不匹配。

¥If the regex is Unicode-unaware, case mapping uses the Unicode Default Case Conversion — the same algorithm used in String.prototype.toUpperCase(). For example, (U+2126 OHM SIGN) and Ω (U+03A9 GREEK CAPITAL LETTER OMEGA) are both mapped by Default Case Conversion to themselves but by simple case folding to ω (U+03C9 GREEK SMALL LETTER OMEGA), so "ω" is matched by /[\u2126]/ui and /[\u03a9]/ui but not by /[\u2126]/i or /[\u03a9]/i. 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.

ignoreCase 的集合访问器是 undefined。你不能直接更改此属性。

¥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

规范

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

¥Specifications

浏览器兼容性

BCD tables only load in the browser

¥Browser compatibility

也可以看看