Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

leftContext Property ($`) (RegExp) (JavaScript)

Returns the characters from the beginning of a searched string up to the position before the beginning of the last match. Read-only.

RegExp.leftContext

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

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

The following example illustrates the use of the leftContext 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);

Supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards, Internet Explorer 8 standards, Internet Explorer 9 standards, Internet Explorer 10 standards, Internet Explorer 11 standards. Also supported Store apps (Windows 8 and Windows Phone 8.1). See Version Information.

Applies To: RegExp Object (JavaScript)

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2015 Microsoft