RegExp.compile

Compiles a regular expression object during execution of a script.

Method of RegExp

Syntax

regexp.compile( pattern[, flags] )

Parameters

Parameter Description
regexp The name of the regular expression. It can be a variable name or a literal.
pattern A string containing the text of the regular expression.
flags If specified, flags can have one of the following values:
"g": global match
"i": ignore case
"gi": both global match and ignore case

Description

Use the compile method to compile a regular expression created with the RegExp constructor function. This forces compilation of the regular expression once only which means the regular expression isn't compiled each time it is encountered. Use the compile method when you know the regular expression will remain constant (after getting its pattern) and will be used repeatedly throughout the script.

You can also use the compile method to change the regular expression during execution. For example, if the regular expression changes, you can use the compile method to recompile the object for more efficient repeated use.

Calling this method changes the value of the regular expression's RegExp.source, RegExp.global, and RegExp.ignoreCase properties.

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.