You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: examples in regexp/@@matchall/index.md (mdn#19898)
- [x] fix typo from `.match` to `.matchAll`
- [x] fix erroneous outputs from a couple examples (expected output was that of `.match`, not `.matchAll`)
- [x] change some single quotes to double, add padding around array literal brackets (for consistent style)
- [x] move some of the expected output comments to new lines (for improved readability)
- [x] fix some other minor grammar and syntax issues
Copy file name to clipboardExpand all lines: files/en-us/web/javascript/reference/global_objects/regexp/@@matchall/index.md
+25-17Lines changed: 25 additions & 17 deletions
Original file line number
Diff line number
Diff line change
@@ -37,34 +37,38 @@ An [iterable iterator](/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators
37
37
This method is called internally in {{jsxref("String.prototype.matchAll()")}}. For example, the following two examples return the same result.
38
38
39
39
```js
40
-
'abc'.matchAll(/a/g);
40
+
"abc".matchAll(/a/g);
41
41
42
-
/a/g[Symbol.matchAll]('abc');
42
+
/a/g[Symbol.matchAll]("abc");
43
43
```
44
44
45
45
Like [`@@split`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/@@split), `@@matchAll` starts by using [`@@species`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/@@species) to construct a new regex, thus avoiding mutating the original regexp in any way. [`lastIndex`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex) starts as the original regex's value.
The validation that the input is a global regex happens in [`String.prototype.matchAll()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/matchAll). `@@matchAll` does not validate the input. If the regex is not global, the returned iterator yields the [`exec()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec) result once and then returns `undefined`. If the regexp is global, each time the returned iterator's `next()` method is called, the regex's [`exec()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec) is called and the result is yielded.
56
56
57
-
When the regex is sticky and global, it would still perform sticky matches — i.e. it would fail to match any occurrences beyond the `lastIndex`.
57
+
When the regex is sticky and global, it will still perform sticky matches — i.e. it will not match any occurrences beyond the `lastIndex`.
If the current match is an empty string, the [`lastIndex`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex)would still be advanced — if the regex has the [`u`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/unicode) flag, it would advance by one Unicode codepoint; otherwise, it advances by one UTF-16 code unit.
64
+
If the current match is an empty string, the [`lastIndex`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex)will still be advanced. If the regex has the [`u`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/unicode) flag, it advances by one Unicode codepoint; otherwise, it advances by one UTF-16 codepoint.
0 commit comments