HTML and CSS Reference
In-Depth Information
EXPLANATION ( CONTINUED )
8
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/.
9
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.
17.3 String Methods Using Regular Expressions
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
Method
What It Does
match(regex)
Returns substring in regex or null.
replace(regex, replacement)
Substitutes regex with replacement string.
search(regex)
Finds the starting position of regex in string.
split(regex)
Removes regex from string for each occurrence.
17.3.1 The match() Method
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.
 
 
 
Search WWH ::




Custom Search