RegExp.$1,$2,..$9

JavaScript 1.2+, JScript 3.0+ Nav4+, NES3+, IE4+ Syntax

RegExp.$1,$2,..$9

Description

The RegExp.$1,$2,..$9 property represents parenthesized substring matches.

Example

Listing 6.213 shows how RegExp.$1,$2,..$9 is used. The user will enter his or her phone number in the input text box and, when the button is clicked, the swap function swaps the last 4 digits in the phone number with the first three.

Listing 6.213 Example of RegExp.$1,$2,..$9
 <html> <body> <script language="JavaScript1.2"> <!–– Hide // function takes the input and swaps the last 4 digits with the // first three digits function swap(){ re = /(\w+)\D(\w+)/; str = document.form1.text1.value; newstr=str.replace(re, "$2, $1"); document.form1.text2.value ...

Get Pure JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.