An RegExp object (new in JavaScript 1.2) corresponds to a regular expression
-
Regular expressions were popular in Perl and JavaScript implementation is modeled on this version
|
There are two syntax's for defining regular expressions: regexp1 = new RegExp( "pattern" ); // or regexp1 = new RegExp( "pattern","flags" ); regexp2 = /pattern/flags; // no quotes
|
Flags are g (match to all occurences) and i (ignore case) or of course gi
|
The latter literal version "compiles" the pattern and is equivalent to
-
regexp2 = regexp1.compile("pattern")
-
Compilation is done for efficiency
|
The RegExp object has two other methods: exec(str) and test(str)and we can also invoke regular expression processing using new String object methods
|
There are both static (as in RegExp.input) and dynamic (as in regexp1.global) properties of regular expressions
|