JavaScript RegExp i modifier

Definition and usage

"i" modifier specifies case-insensitive matching.

Instance

Example 1

Perform a case-insensitive search for "is":

let text = "Visit CodeW3C.com";
let pattern = /codew3c/i;
let result = text.match(pattern);

Try it yourself

Example 2

Perform a case-insensitive search for "codew3c" in the string:

Using regular expression function exec():

let text = "Visit codew3c";
let pattern = /codew3c/i;
let result = pattern.exec(text);

Try it yourself

Example 3

Using regular expression functions test():

let text = "Visit CodeW3C.com";
let pattern = /codew3c/i;
let result = pattern.test(text);

Try it yourself

Example 4

Using string functions match():

let text = "Visit CodeW3C.com";
let pattern = /codew3c/i;
let result = text.match(pattern);

Try it yourself

Syntax

new RegExp("regexp", "i")

Or abbreviated as:

/regexp/i

Prompt

You can use ignoreCase Property checks whether the "i" modifier is set.

let pattern = /W3S/i;
let result = pattern.ignoreCase;

Try it yourself

Regular expression search methods

In JavaScript, regular expression text search can be completed with different methods.

UsagePattern (pattern)As regular expressions, these are the most commonly used methods:

Example Description
text.match(pattern) String method match()
text.search(pattern) String method search()
pattern.exec(text) RexExp method exec()
pattern.test(text) RexExp method test()

Browser support

/regexp/i Is ECMAScript1 (ES1) feature.

All browsers fully support ES1 (JavaScript 1997):

Chrome IE Edge Firefox Safari Opera
Support Support Support Support Support Support