PROPERTY:  RegExp::leftContextNetscape Only Feature


RegExp.leftContext
 

 
This property is the substring upto the character most recently matched (i.e. everything that comes before it), and as a static property, is always used as RegExp.leftContext. Consider the following code. The regular expression consists of one or more vowels. The code searches the string "the fisherman" and matches the 'e' in 'the' printing the substring to the left of it: namely 'th'. Then it searches the same string again from where it ended the previous search (see the lastIndex property), this time matching the 'i' of 'fisherman' and printing the preceding substring 'the f'.
 
Code:
rexp = /[aeiou]+/g
rexp("the fisherman")
document.write(RegExp.leftContext)
rexp("the fisherman")
document.write("<BR>" + RegExp.leftContext)

 
Output:
th
the f

 
NOTE:
 
The regular expression in the above example uses the flag 'g' to indicate a global search. If it wasn't there, the second search in the above example would start at the beginning of the string producing exactly the same match as the first search: namely 'th'.


Copyright 1999-2001 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information