HTML and CSS Reference
EXPLANATION ( CONTINUED )
leftContext is a class property that represents the leftmost substring pattern that pre-
cedes the last pattern that was matched; here, whatever string comes before /love/.
rightContext is a class property that represents the rightmost substring pattern that
follows the last pattern that was matched; here, whatever string comes after /love/ .
Output is shown in Figure 17.5.
Figure 17.5 Regular expression properties.
In addition to the RegExp object's test() and exec() methods, the String object provides
four methods that also work with regular expressions, as shown in Table 17.5.
Table 17.5 String Object Regular Expression Methods
What It Does
Returns substring in regex or null.
Substitutes regex with replacement string.
Finds the starting position of regex in string.
Removes regex from string for each occurrence.
The match() method, like the exec() method, is used to search for a pattern of characters
in a string and returns an array where each element of the array contains each matched
pattern that was found. If no match is found, returns null . With the g flag, match()
searches globally through the string for all matching substrings.