2.4.8.1 RegExp.prototype.compile(pattern, flags)

If pattern is an object R that has a [[Class]] property "RegExp" and flags is undefined, let P be the pattern used to construct R and let F be the flags used to construct R. If pattern is an object R that has a [[Class]] property "RegExp" and flags is not undefined, raise a RegExpError exception. Otherwise, let P be the empty string if pattern is undefined and ToString(pattern) otherwise, and let F be the empty string if flags is undefined and ToString(flags) otherwise.

The global property of this RegExp object is set to a Boolean value that is true if F contains the character "g" and that is false otherwise.

The ignoreCase property of this RegExp object is set to a Boolean value that is true if F contains the character "i" and that is false otherwise.

The multiline property of this RegExp object is set to a Boolean value that is true if F contains the character "m" and that is false otherwise.

If F contains any character other than "g", "i", or "m", raise a RegExpError exception.

If P's characters do not have the form Pattern, raise a RegExpError exception. Otherwise, let the newly constructed object have a [[Match]] property obtained by evaluating ("compiling") Pattern. Note that evaluating Pattern may raise a RegExpError exception. (Note: if pattern is a StringLiteral, the usual escape sequence substitutions are performed before the string is processed by RegExp. If pattern must contain an escape sequence to be recognized by RegExp, the "\" character must be escaped within the StringLiteral to prevent its being removed when the contents of the StringLiteral are formed.)

The source property of this RegExp object is set as follows:

When pattern is an object R that has a [[Class]] property of "RegExp", this RegExp object is set to the same string value as the value of the source property of pattern. Otherwise, the source property of this RegExp object is set to P.

The lastIndex property of this RegExp object is set to 0.

The options property of this RegExp object is set as described in section 2.4.9.1.

This RegExp object is optimized using the assumption that it will be executed multiple times.

Show: