| leftContext The leftContext property is a property of the RegExp object, and represents the string (of text, usually) which appears before the most recent pattern match. syntax: RegExp.leftContext EXAMPLE globalRegExp = /the* /gi; var stringToSearch = "This is the RegExp search Text"; searchArray = globalRegExp.exec(stringToSearch); document.write("This is the RegExp search Result, leftContext : " + RegExp.leftContext); The first variable in the example (globalRegExp) specifies the text to search for ("the"), and the two switches to refine the search ("/gi"). See the RegExp object for a full list of search refining switches. The second variable, stringToSearch, contains the text that will be searched for a match to the search string set by globalRegExp. The searchArray contains the globalRegExp Object, with the exec() method, which performs the actual string search. The string to search through is given in the brackets, represented by the stringToSearch variable. Finally, the document.write statement writes a caption to the screen, along with the RegExp.leftContext contents. The string that is written to the screen should look like this: This is the RegExp search Result, leftContext : This is The example returned the string which exists before (to the left of) the word "the". Hence the wording of "leftContext". |