RegExp.compile()

JavaScript 1.2+, JScript 3.0+ Nav4+, NES3+, IE4+ Syntax

							regexp.compile(pattern,
							flag)

Description

The compile() method of the RegExp object compiles a regular expression object. The creation of the object takes pattern and flags parameters. The pattern is a valid regular expression. The flags are either or both g (global) and i (ignore case).

Example

Listing 6.214 shows how to use the compile() method. A pattern is created using the RegExp constructor. It is then compiled using the compile method, and the result is displayed in the text area.

Listing 6.214 Example of compile() Method
 <html> <body> <script language="JavaScript"> <!–– Hide var myPat = new RegExp("jane", "i"); var newPat = myPat.compile(myPat); ...

Get Pure JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.