From 074785cea106179cb3305637055ab0a009ca74f2 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:42:52 -0500 Subject: initial commit --- .../global_objects/symbol/matchall/index.html | 72 ++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 files/pt-br/web/javascript/reference/global_objects/symbol/matchall/index.html (limited to 'files/pt-br/web/javascript/reference/global_objects/symbol/matchall/index.html') diff --git a/files/pt-br/web/javascript/reference/global_objects/symbol/matchall/index.html b/files/pt-br/web/javascript/reference/global_objects/symbol/matchall/index.html new file mode 100644 index 0000000000..7874646623 --- /dev/null +++ b/files/pt-br/web/javascript/reference/global_objects/symbol/matchall/index.html @@ -0,0 +1,72 @@ +--- +title: Symbol.matchAll +slug: Web/JavaScript/Reference/Global_Objects/Symbol/matchAll +translation_of: Web/JavaScript/Reference/Global_Objects/Symbol/matchAll +--- +
{{JSRef}}
+ +

O símbolo Symbol.matchAll é conhecido por retornar um iterador, que produz conrrespondências de uma expressão regular com uma string. Essa função é usada pelo método {{jsxref("String.prototype.matchAll()")}}.

+ +
{{EmbedInteractiveExample("pages/js/symbol-matchall.html","shorter")}}
+ + + +

Descrição

+ +
+

Esse símbolo é usado pelo {{jsxref("String.prototype.matchAll()")}} e especificado no {{jsxref("RegExp.@@matchAll", "RegExp.prototype[@@matchAll]()")}}. Os próximos dois exemplos retornam o mesmo resultado:

+ +
'abc'.matchAll(/a/);
+
+/a/[Symbol.matchAll]('abc');
+ +

Esse método existe para costumizar o comportamento conrrespondente com as subclasses {{jsxref("RegExp")}}.

+ +

{{js_property_attributes(0,0,0)}}

+
+ +

Exemplos

+ +

Usuando Symbol.matchAll

+ +
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"]
+
+ +

Veja {{jsxref("String.prototype.matchAll()")}} e {{jsxref("RegExp.@@matchAll", "RegExp.prototype[@@matchAll]()")}} para mais exemplos.

+ +

Especificações

+ + + + + + + + + + +
Especificação
{{SpecName('ESDraft', '#sec-symbol.matchall', 'Symbol.matchAll')}}
+ +

Compatibilidade de navegador

+ + + +

{{Compat("javascript.builtins.Symbol.matchAll")}}

+ +

Veja também

+ + -- cgit v1.2.3-54-g00ecf