Easy Tutorial
❮ Met Table Createthead Prop Frame Src ❯

JavaScript compile() Method


Definition and Usage

The compile() method is used to compile a regular expression during script execution.

The compile() method can also be used to change and recompile a regular expression.

Syntax

Parameter Description
regexp The regular expression.
modifier Specifies the type of matching. "g" for global matching, "i" for case-insensitive matching, "gi" for global case-insensitive matching.

Browser Support

All browsers support the compile() method except for Opera.


Example

Search globally for "man" in a string and replace it with "person". Then, using the compile() method, change the regular expression to replace "man" or "woman" with "person":

The above example outputs:

❮ Met Table Createthead Prop Frame Src ❯