forked from nkronlage/JavaScripture
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathregexp.jsdoc
More file actions
164 lines (117 loc) · 3.89 KB
/
regexp.jsdoc
File metadata and controls
164 lines (117 loc) · 3.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
RegExp : Object
RegExp represents a regular expression that can be used for
searching and extracting parts of %%/String|**String**%%s.
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.10
----
RegExp(pattern : String, [flags : String]) : RegExp
Same as %%#new_RegExp_String_String|**new RegExp(pattern, flags)**%%.
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.10.3.1
----
new RegExp(pattern : String, [flags : String]) : RegExp
Constructs a new **RegExp** for the specified **pattern**.
If **flags** contains **'g'**, %%#global|**this.global**%% will be set to **true**.
If **flags** contains **'i'**, %%#ignoreCase|**this.ignoreCase**%% will be set to **true**.
If **flags** contains **'m'**, %%#multiline|**this.multiline**%% will be set to **true**.
**RegExp**s can also be constructed using **/pattern/flags** syntax.
<example>
// The following are equivalent
var x = /pattern/i;
var y = RegExp('pattern', 'i');
var z = new RegExp('pattern', 'i');
</example>
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.10.4.1
----
prototype.exec(str : String) : Array<String>
If **this** matches **str**, returns a new **Array** with item **0** equal to the
portion of **str** that matched the regular expression, item **1** equal to the first
capturing group in **this**, item **2** equal to the second capturing group in **this**,
and so on. If **this** doesn't match **str**, returns **null**.
<example>
var regexp = /(\d\d\d)-(\d\d\d\d)/;
var result = regexp.exec('call me: 555-4385');
if (result) {
console.log(result[0]);
console.log(result[1]);
console.log(result[2]);
}
</example>
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.10.6.2
----
prototype.test(str : String) : Boolean
Returns **true** if **this** matches **str**.
<example>
var regexp = /(\d\d\d)-(\d\d\d\d)/;
console.log(regexp.test('555-4385'));
console.log(regexp.test('KL5-4385'));
</example>
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.10.6.3
----
instance.source : String
The pattern of this regular expression.
<example>
var regexp = /(\d\d\d)-(\d\d\d\d)/;
console.log(regexp);
console.log(regexp.source);
</example>
ReadOnly:
true
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.10.7.1
----
instance.global : Boolean
**true** if the **RegExp** was created with the **'g'** flag. Global
**RegExp**s will match each place %%#source|**this.source**%% occurs in the string, not
just the first match.
<example>
console.log('abcba'.replace(/b/, 'X'));
console.log('abcba'.replace(/b/g, 'X'));
</example>
ReadOnly:
true
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.10.7.2
----
instance.ignoreCase : Boolean
**true** if the **RegExp** was created with the **'i'** flag. IgnoreCase
**RegExp**s will do case insensitive matching.
<example>
console.log(/hello/.test('Hello'));
console.log(/hello/i.test('Hello'));
</example>
ReadOnly:
true
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.10.7.3
----
instance.multiline : Boolean
**true** if the **RegExp** was created with the **'m'** flag. Multiline
**RegExp**s will match **'^'** to the beginning of lines as well as the
beginning of the string and match **'$'** to the end of lines as well as
the end of the string.
<example>
var str = 'hello\nworld';
console.log(/^world/.test(str));
console.log(/^world/m.test(str));
</example>
ReadOnly:
true
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.10.7.4
----
instance.lastIndex : Number
The starting index into the string for the next search. Is automatically set to the
index after a successful match. This property only applies if the **RegExp** is %%#global|**global**%%.
<example>
var regexp = /foo|bar|baz/g;
console.log(regexp.exec('foo bar baz')[0]);
console.log(regexp.lastIndex);
regexp.lastIndex = 5;
console.log(regexp.exec('foo bar baz')[0]);
</example>
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.10.7.5