1 |
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
|
2 |
There are two syntax's for defining regular expressions: regexp1 = new RegExp( "pattern" ); // or regexp1 = new RegExp( "pattern","flags" ); regexp2 = /pattern/flags; // no quotes
|
3 |
Flags are g (match to all occurences) and i (ignore case) or of course gi
|
4 |
The latter literal version "compiles" the pattern and is equivalent to
-
regexp2 = regexp1.compile("pattern")
-
Compilation is done for efficiency
|
5 |
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
|
6 |
There are both static (as in RegExp.input) and dynamic (as in regexp1.global) properties of regular expressions
|