2
* File Name: String/match-001.js
3
* ECMA Section: 15.6.4.9
4
* Description: Based on ECMA 2 Draft 7 February 1999
6
* Author: christine@netscape.com
7
* Date: 19 February 1999
11
* String.match( regexp )
13
* If regexp is not an object of type RegExp, it is replaced with result
14
* of the expression new RegExp(regexp). Let string denote the result of
15
* converting the this value to a string. If regexp.global is false,
16
* return the result obtained by invoking RegExp.prototype.exec (see
17
* section 15.7.5.3) on regexp with string as parameter.
19
* Otherwise, set the regexp.lastIndex property to 0 and invoke
20
* RegExp.prototype.exec repeatedly until there is no match. If there is a
21
* match with an empty string (in other words, if the value of
22
* regexp.lastIndex is left unchanged) increment regexp.lastIndex by 1.
23
* The value returned is an array with the properties 0 through n-1
24
* corresponding to the first element of the result of each matching
25
* invocation of RegExp.prototype.exec.
27
* Note that the match function is intentionally generic; it does not
28
* require that its this value be a string object. Therefore, it can be
29
* transferred to other kinds of objects for use as a method.
32
var SECTION = "String/match-001.js";
33
var VERSION = "ECMA_2";
34
var TITLE = "String.prototype.match( regexp )";
38
// the regexp argument is not a RegExp object
39
// this is not a string object
41
// cases in which the regexp global property is false
43
AddRegExpCases( 3, "3", "1234567890", 1, 2, ["3"] );
45
// cases in which the regexp object global property is true
47
AddGlobalRegExpCases( /34/g, "/34/g", "343443444", 3, ["34", "34", "34"] );
48
AddGlobalRegExpCases( /\d{1}/g, "/d{1}/g", "123456abcde7890", 10,
49
["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"] );
51
AddGlobalRegExpCases( /\d{2}/g, "/d{2}/g", "123456abcde7890", 5,
52
["12", "34", "56", "78", "90"] );
54
AddGlobalRegExpCases( /\D{2}/g, "/d{2}/g", "123456abcde7890", 2,
60
function AddRegExpCases(
61
regexp, str_regexp, string, length, index, matches_array ) {
64
"( " + string + " ).match(" + str_regexp +").length",
66
string.match(regexp).length );
69
"( " + string + " ).match(" + str_regexp +").index",
71
string.match(regexp).index );
74
"( " + string + " ).match(" + str_regexp +").input",
76
string.match(regexp).input );
78
for ( var matches = 0; matches < matches_array.length; matches++ ) {
80
"( " + string + " ).match(" + str_regexp +")[" + matches +"]",
81
matches_array[matches],
82
string.match(regexp)[matches] );
86
function AddGlobalRegExpCases(
87
regexp, str_regexp, string, length, matches_array ) {
90
"( " + string + " ).match(" + str_regexp +").length",
92
string.match(regexp).length );
94
for ( var matches = 0; matches < matches_array.length; matches++ ) {
96
"( " + string + " ).match(" + str_regexp +")[" + matches +"]",
97
matches_array[matches],
98
string.match(regexp)[matches] );