The RegExp ObjectBesides regular expression objects, there is also a global object named RegExp that holds data about the most recent regular expression operation. This object always existsdon't confuse it with regular expression objects of the kind just covered. The global RegExp object holds data about the most recent regular expression operation, whereas regular expression objects hold data about their particular regular expression operations. You can find the properties of the RegExp object in Table 20.4. Table 20.4. The Properties of the RegExp Object
The RegExp object is a global one, and to use properties such as $1 through $9 , which refer to parenthesized submatches, you can just use $1 through $9 in your code. In fact, we've already seen that when we used those properties to reverse the order of three words (from Listing 20-09.html): <HTML> <HEAD> <TITLE>The Reverser</TITLE> <SCRIPT LANGUAGE="JavaScript"> <!-- function reversem() { var regexp =/(\w+)\s*(\w+)\s*(\w+)/ document.form1.text1.value = document.form1.text1.value.replace(regexp, " ") } //--> </SCRIPT> </HEAD> . . . </HTML> That's it for our look at regular expressions in this chapter. As you can see, there's a terrific amount of powerand complexityavailable if you need to work with matching and extracting text. In the next chapter, we'll keep going with text handlingand handling other elements such as imagesas we start working with Cascading Style Sheets (CSS) in depth. |