Partager via


lastMatch Property ($&) (Windows Scripting - JScript)

 

Returns the last matched characters from any regular expression search. Read-only.

Syntax

RegExp.lastMatch

Remarks

The object associated with this property is always the global RegExp object.

The initial value of the lastMatch property is an empty string. The value of the lastMatch property changes whenever a successful match is made.

The following example illustrates the use of the lastMatch property:

   // Create the regular expression pattern.
   var re = new RegExp("d(b+)(d)","ig");
   var str = "cdbBdbsbdbdz";

   // Perform the search.
   var arr = re.exec(str);

   // Print the output.
   var s = "" 
   s += "$1: " + RegExp.$1 + "<br />";
   s += "$2: " + RegExp.$2 + "<br />";
   s += "$3: " + RegExp.$3 + "<br />";
   s += "input: " + RegExp.input + "<br />";
   s += "lastMatch: " + RegExp.lastMatch + "<br />";
   s += "leftContext: " + RegExp.leftContext + "<br />";
   s += "rightContext: " + RegExp.rightContext + "<br />"; 
   s += "lastParen: " + RegExp.lastParen + "<br />";

   document.write(s);

Requirements

Version 5.5

Applies To: RegExp Object (Windows Scripting - JScript)

Change History

Date

History

Reason

March 2009

Modified example,

Information enhancement.

See Also

$1...$9 Properties (Windows Scripting - JScript)
index Property (Windows Scripting - JScript)
input Property ($_) (Windows Scripting - JScript)
lastIndex Property (Windows Scripting - JScript)
lastParen Property ($+) (Windows Scripting - JScript)
leftContext Property ($`) (Windows Scripting - JScript)
rightContext Property ($') (Windows Scripting - JScript)