From 980fe00a74a9ad013b945755415ace2e5429c3c2 Mon Sep 17 00:00:00 2001 From: Alexey Pyltsyn Date: Wed, 27 Oct 2021 02:31:24 +0300 Subject: [RU] Remove notranslate (#2874) --- .../reference/global_objects/string/matchall/index.html | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'files/ru/web/javascript/reference/global_objects/string/matchall') diff --git a/files/ru/web/javascript/reference/global_objects/string/matchall/index.html b/files/ru/web/javascript/reference/global_objects/string/matchall/index.html index 1ffad309c2..f314d2f18c 100644 --- a/files/ru/web/javascript/reference/global_objects/string/matchall/index.html +++ b/files/ru/web/javascript/reference/global_objects/string/matchall/index.html @@ -20,7 +20,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/matchAll

Синтаксис

-
str.matchAll(regexp)
+
str.matchAll(regexp)

Параметры

@@ -39,7 +39,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/String/matchAll

До добавления метода matchAll в JavaScript, можно было использовать метод regexp.exec (и регулярные выражения с флагом /g ) в цикле для получения доступа к совпадениям:

-
const regexp = RegExp('foo*','g');
+
const regexp = RegExp('foo*','g');
 const str = 'table football, foosball';
 
 while ((matches = regexp.exec(str)) !== null) {
@@ -52,7 +52,7 @@ while ((matches = regexp.exec(str)) !== null) {
 

С появлением matchAll, нет необходимости использовать цикл while и метод exec с флагом /g.
Используя вместо этого метод matchAll, вы получаете итератор, который вы можете использовать более удобно с конструкциями for...of, array spread, или {{jsxref("Array.from()")}} :

-
const regexp = RegExp('foo*','g');
+
const regexp = RegExp('foo*','g');
 const str = 'table football, foosball';
 let matches = str.matchAll(regexp);
 
@@ -74,7 +74,7 @@ Array.from(matches, m => m[0]);
 
 

Ещё одна веская причина использовать matchAll это улучшенный доступ к группам захвата. Группы захвата игнорируются при использовании match() с глобальным флагом /g:

-
var regexp = /t(e)(st(\d?))/g;
+
var regexp = /t(e)(st(\d?))/g;
 var str = 'test1test2';
 
 str.match(regexp);
@@ -82,7 +82,7 @@ str.match(regexp);
 
 

С matchAll у вас появляется к ним доступ:

-
let array = [...str.matchAll(regexp)];
+
let array = [...str.matchAll(regexp)];
 
 array[0];
 // ['test1', 'e', 'st1', '1', index: 0, input: 'test1test2', length: 4]
-- 
cgit v1.2.3-54-g00ecf