Specifications

A regular expression can be set to global either by setting the global
property on a regexp object or by specifying a trailing g in the pattern.
var re = /mypattern/g; // Global by method #1
var re = /mypattern/;
re.global = true // Global by method #2
Specifies that the regexp ignores case when matching.
Case-insensitivity can is enabled by either specifying a trailing i after
the pattern or by setting the ignoreCase property.
var re = /mypattern/i; // Case-insensitive by method #1
ignoreCase : Boolean
var re = /mypattern/;
re.ignoreCase = true; // Case-insensitive by method #2
RegExp Functions
Returns the regular expression pattern as a string.
toString() : String
Searches text for the pattern defined by the regular expression. The
function returns the position in the text of the first match or -1 if
no match is found.
var re = /\d+ cm/; // matches one or more digits followed
search( text : String) :
Number
by space then 'cm'
re.search( "A meter is 100 cm long" ); // returns 11
Same as search(), but searchRev searches from the end of the text.
searchRev( text : String) :
Number
Returns true if text exactly matches the pattern in this regular
expression; otherwise returns false.
exactMatch( text : String)
: Boolean
Returns the nth capture of the pattern in the previously matched
text. The first captured string (cap(0) ) is the part of the string that
cap( nth : Number ) :
String
matches the pattern itself, if there is a match. The following
captured strings are the parts of the pattern enclosed by
parenthesis. In the above example, we try to capture ([a-zA-Z ]+),
which captures a sequence of one or more letters and spaces after
the name: part of the string.
re = /name: ([a-zA-Z ]+)/;
re.search( "name: John Doe, age: 42" );
re.cap(0); // returns "name: John Doe"
re.cap(1); // returns "John Doe"
re.cap(2); // returns undefined, no more captures.
Returns the position of the nth captured text in the search string.
re = /name: ([a-zA-Z ]+)/;
pos( nth : Number ) :
Number
re.search( "name: John Doe, age: 42" );
re.pos(0); // returns 0, position of "name: John Doe"
382
Enfocus Switch 10