JavaScript tutorial:
RegExp object

 

Methods

Properties

The RegExp object is use to store information on regular expression pattern searches.

Syntax

RegExp.propertyname

The propertyname argument is one of the RegExp object properties.

Example

The RegExp object cannot be created directly, but is always available for use. Its properties have undefined as their value until a successful regular expression search has been completed.

The following example illustrates the use of the RegExp object:

function matchDemo()
{
var s;
var re = new RegExp("d(b+)(d)","ig");
var str = "cdbBdbsbdbdz";
var arr = re.exec(str);
s = "$1 contains: " + RegExp.$1 + "<BR>";
s += "$2 contains: " + RegExp.$2 + "<BR>";
s += "$3 contains: " + RegExp.$3;
return(s);
}
document.write(matchDemo());

  To run the code above, paste it into JavaScript Editor, and click the Execute butto.

See also: Regular Expression Object, Regular Expression Syntax, String Object