Symbol.matchAll
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2015.
Symbol.matchAll
は静的データプロパティで、ウェルノウンシンボルである Symbol.match
を表します。String.prototype.matchAll()
メソッドは最初の引数に対して、文字列に対する現在のオブジェクトの照合を行うイテレーターを返すメソッドを、このシンボルで探します。
詳しくは、RegExp.prototype[Symbol.matchAll]()
および String.prototype.matchAll()
を参照してください。
試してみましょう
const re = /[0-9]+/g;
const str = "2016-01-02|2019-03-07";
const result = re[Symbol.matchAll](str);
console.log(Array.from(result, (x) => x[0]));
// Expected output: Array ["2016", "01", "02", "2019", "03", "07"]
値
ウェルノウンシンボル Symbol.matchAll
です。
Symbol.matchAll のプロパティ属性 | |
---|---|
書込可能 | 不可 |
列挙可能 | 不可 |
設定可能 | 不可 |
例
Symbol.matchAll の使用
js
const 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)));
// ["2016", "01", "02", "2019", "03", "07"]
仕様書
Specification |
---|
ECMAScript® 2025 Language Specification # sec-symbol.matchall |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
matchAll |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.