diff options
Diffstat (limited to 'files/ja/web/javascript/reference/global_objects/symbol/matchall/index.html')
| -rw-r--r-- | files/ja/web/javascript/reference/global_objects/symbol/matchall/index.html | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/files/ja/web/javascript/reference/global_objects/symbol/matchall/index.html b/files/ja/web/javascript/reference/global_objects/symbol/matchall/index.html new file mode 100644 index 0000000000..e973cd69ba --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/symbol/matchall/index.html @@ -0,0 +1,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> |
