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
|
---
title: Symbol.matchAll
slug: Web/JavaScript/Reference/Global_Objects/Symbol/matchAll
tags:
- JavaScript
- Property
- Reference
- Symbol
translation_of: Web/JavaScript/Reference/Global_Objects/Symbol/matchAll
---
<div>{{JSRef}}</div>
<p><strong><code>Symbol.matchAll</code></strong> は、文字列に対する正規表現の一致を生成するイテレーターを返します。この関数は {{jsxref("String.prototype.matchAll()")}} メソッドによって呼び出されます。</p>
<div>{{EmbedInteractiveExample("pages/js/symbol-matchall.html","shorter")}}</div>
<h2 id="Description" name="Description">説明</h2>
<div>
<p>このシンボルは {{jsxref("String.prototype.matchAll()")}}、特に {{jsxref("RegExp.@@matchAll", "RegExp.prototype[@@matchAll]()")}} で使用されます。以下の 2 つの例は同じ結果を返します。</p>
<pre class="brush: js notranslate">'abc'.matchAll(/a/);
/a/[Symbol.matchAll]('abc');</pre>
<p>このメソッドは、{{jsxref("RegExp")}} サブクラス内の一致動作をカスタマイズするために存在します。</p>
<p>{{js_property_attributes(0,0,0)}}</p>
</div>
<h2 id="Examples" name="Examples">例</h2>
<h3 id="Using_Symbol.matchAll" name="Using_Symbol.matchAll">Symbol.matchAll を使用する</h3>
<pre class="brush: js notranslate">let re = /[0-9]+/g;
let str = '2016-01-02|2019-03-07';
const numbers = {
*[Symbol.matchAll] (str) {
for (const n of str.matchAll(/[0-9]+/g))
yield n[0];
}
};
console.log(Array.from(str.matchAll(numbers)));
// Array ["2016", "01", "02", "2019", "03", "07"]
</pre>
<p>その他の例については、{{jsxref("String.prototype.matchAll()")}} と {{jsxref("RegExp.@@matchAll", "RegExp.prototype[@@matchAll]()")}} を参照してください。</p>
<h2 id="Specifications" name="Specifications">仕様</h2>
<table class="standard-table">
<tbody>
<tr>
<th scope="col">仕様書</th>
</tr>
<tr>
<td>{{SpecName('ESDraft', '#sec-symbol.matchall', 'Symbol.matchAll')}}</td>
</tr>
</tbody>
</table>
<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザー実装状況</h2>
<p>{{Compat("javascript.builtins.Symbol.matchAll")}}</p>
<h2 id="See_also" name="See_also">関連情報</h2>
<ul>
<li>{{jsxref("String.prototype.matchAll()")}}</li>
<li>{{jsxref("RegExp.@@matchAll", "RegExp.prototype[@@matchAll]()")}}</li>
</ul>
|