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
|
---
title: RegExp.prototype
slug: conflicting/Web/JavaScript/Reference/Global_Objects/RegExp
tags:
- JavaScript
- Property
- RegExp
translation_of: Web/JavaScript/Reference/Global_Objects/RegExp
translation_of_original: Web/JavaScript/Reference/Global_Objects/RegExp/prototype
original_slug: Web/JavaScript/Reference/Global_Objects/RegExp/prototype
---
<p>{{JSRef("Global_Objects", "RegExp")}}</p>
<h2 id="Summary" name="Summary">概述</h2>
<p><font face="Courier New, Andale Mono, monospace">RegExp.prototype 属性表示 </font><span style="line-height: 1.5;">{{jsxref("Global_Objects/RegExp", "RegExp")}} </span><span style="font-family: 'Courier New', 'Andale Mono', monospace; line-height: 1.5;">构造函数的原型对象。</span></p>
<h2 id="Description" name="Description">描述</h2>
<p>查看<font face="Courier New, Andale Mono, monospace"> </font><span style="line-height: 1.5;">{{jsxref("Global_Objects/RegExp", "RegExp")}} </span><span style="line-height: 1.5;">了解更多关于 </span><code style="font-style: normal; line-height: 1.5;">RegExp</code> <code style="font-style: normal; line-height: 1.5;">实例的说明。</code></p>
<p><code>RegExp</code> 实例继承 <code>RegExp.prototype</code>。修改该原型对象上的属性或方法会影响到所有的 <code>RegExp</code> <code>实例。</code></p>
<h2 id="Properties" name="Properties">属性</h2>
<p>查看<a href="/zh-CN/docs/JavaScript/Reference/Deprecated_Features#RegExp_Properties" title="zh-CN/docs/JavaScript/Reference/Deprecated_Features#RegExp_Properties">已废弃的RegExp属性</a></p>
<p>注意,<code>RegExp</code> 对象的几个属性既有完整的长属性名,也有对应的类 Perl 的短属性名。两个属性都有着同样的值。JavaScript 的正则语法就是基于 Perl 的。</p>
<dl>
<dt>
<code style="font-style: normal; font-weight: bold;">RegExp.prototype.</code><code style="font-style: normal; font-weight: bold;">constructor</code></dt>
<dd>
创建该正则对象的构造函数。</dd>
<dt>
{{jsxref("RegExp.prototype.global")}}</dt>
<dd>
是否开启全局匹配,也就是匹配目标字符串中所有可能的匹配项,而不是只进行第一次匹配。</dd>
<dt>
{{jsxref("RegExp.prototype.ignoreCase")}}</dt>
<dd>
在匹配字符串时是否要忽略字符的大小写。</dd>
<dt>
{{jsxref("RegExp.prototype.lastIndex")}}</dt>
<dd>
下次匹配开始的字符串索引位置。</dd>
<dt>
{{jsxref("RegExp.prototype.multiline")}}</dt>
<dd>
是否开启多行模式匹配(影响 ^ 和 $ 的行为)。</dd>
<dt>
{{jsxref("RegExp.prototype.source")}}</dt>
<dd>
正则对象的源模式文本。</dd>
<dt>
{{jsxref("RegExp.prototype.sticky")}} {{experimental_inline}}</dt>
<dd>
是否开启粘滞匹配。</dd>
</dl>
<div>
{{ jsOverrides("Object", "properties", "constructor", "global", "ignoreCase", "lastIndex", "multiline", "source", "sticky") }}</div>
<h2 id="Methods" name="Methods">方法</h2>
<p>查看<a href="/zh-CN/docs/JavaScript/Reference/Deprecated_Features#RegExp_Methods" title="zh-CN/docs/JavaScript/Reference/Deprecated_Features#RegExp_Methods">已废弃的RegExp方法</a></p>
<dl>
<dt>
{{jsxref("RegExp.prototype.exec()")}}</dt>
<dd>
在目标字符串中执行一次正则匹配操作。</dd>
<dt>
{{jsxref("RegExp.prototype.test()")}}</dt>
<dd>
测试当前正则是否能匹配目标字符串。</dd>
<dt>
{{jsxref("RegExp.prototype.toSource()")}} {{non-standard_inline}}</dt>
<dd>
返回一个字符串,其值为该正则对象的字面量形式。覆盖了<code>Object.prototype.toSource</code> 方法.</dd>
<dt>
{{jsxref("RegExp.prototype.toString()")}}</dt>
<dd>
返回一个字符串,其值为该正则对象的字面量形式。覆盖了{{jsxref("Object.prototype.toString()")}} 方法。</dd>
</dl>
<div>
{{ jsOverrides("Object", "Methods", "exec", "test", "toSource", "toString") }}</div>
<h2 id="规范" style="margin-bottom: 20px; line-height: 30px;">规范</h2>
<table class="standard-table">
<tbody>
<tr>
<th scope="col">Specification</th>
<th scope="col">Status</th>
<th scope="col">Comment</th>
</tr>
<tr>
<td>ECMAScript 1st Edition. Implemented in JavaScript 1.1</td>
<td>Standard</td>
<td>Initial definition.</td>
</tr>
<tr>
<td>{{SpecName('ES5.1', '#sec-15.10.5.1', 'RegExp')}}</td>
<td>{{Spec2('ES5.1')}}</td>
<td> </td>
</tr>
<tr>
<td>{{SpecName('ES6', '#sec-regexp.prototype', 'RegExp.prototype')}}</td>
<td>{{Spec2('ES6')}}</td>
<td> </td>
</tr>
</tbody>
</table>
<h2 id="浏览器兼容性" style="margin-bottom: 20px; line-height: 30px;">浏览器兼容性</h2>
<p>{{ CompatibilityTable() }}</p>
<div id="compat-desktop">
<table class="compat-table">
<tbody>
<tr>
<th style="line-height: 16px;">Feature</th>
<th style="line-height: 16px;">Chrome</th>
<th style="line-height: 16px;">Firefox (Gecko)</th>
<th style="line-height: 16px;">Internet Explorer</th>
<th style="line-height: 16px;">Opera</th>
<th style="line-height: 16px;">Safari</th>
</tr>
<tr>
<td>Basic support</td>
<td>{{ CompatVersionUnknown() }}</td>
<td>{{ CompatVersionUnknown() }}</td>
<td>{{ CompatVersionUnknown() }}</td>
<td>{{ CompatVersionUnknown() }}</td>
<td>{{ CompatVersionUnknown() }}</td>
</tr>
</tbody>
</table>
</div>
<div id="compat-mobile">
<table class="compat-table">
<tbody>
<tr>
<th style="line-height: 16px;">Feature</th>
<th style="line-height: 16px;">Android</th>
<th style="line-height: 16px;">Chrome for Android</th>
<th style="line-height: 16px;">Firefox Mobile (Gecko)</th>
<th style="line-height: 16px;">IE Mobile</th>
<th style="line-height: 16px;">Opera Mobile</th>
<th style="line-height: 16px;">Safari Mobile</th>
</tr>
<tr>
<td>Basic support</td>
<td>{{ CompatVersionUnknown() }}</td>
<td>{{ CompatVersionUnknown() }}</td>
<td>{{ CompatVersionUnknown() }}</td>
<td>{{ CompatVersionUnknown() }}</td>
<td>{{ CompatVersionUnknown() }}</td>
<td>{{ CompatVersionUnknown() }}</td>
</tr>
</tbody>
</table>
</div>
<h2 id="相关链接" style="margin-bottom: 20px; line-height: 30px;">相关链接</h2>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions" title="JavaScript/Guide/Regular_Expressions">Regular Expressions</a> chapter in the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide" title="JavaScript/Guide">JavaScript Guide</a></li>
<li>{{jsxref("Global_Objects/RegExp", "RegExp")}}</li>
<li>{{jsxref("Function.prototype")}}</li>
</ul>
<p> </p>
|