Greedy and lazy quantifiers by SamGreenberg · Pull Request #450 · javascript-tutorial/uk.javascript.info
@@ -1,15 +1,15 @@
We need to find the beginning of the comment `match:<!--`, then everything till the end of `match:-->`.
Нам потрібно знайти початок коментарю `match:<!--`, та його зміст до самого кінця `match:-->`.
An acceptable variant is `pattern:<!--.*?-->` -- the lazy quantifier makes the dot stop right before `match:-->`. We also need to add flag `pattern:s` for the dot to include newlines. Прийнятним є варіант `pattern:<!--.*?-->` -- лінивий квантифікатор зупиняє крапку (будь-який символ, за винятком символу нового рядку) прямо перед `match:-->`. Нам також треба додати прапорець `pattern:s`, аби крапка включала символи нового рядку.
Otherwise multiline comments won't be found: Інакше коментарі на кілька рядків не знаходитимуться:
```js run let regexp = /<!--.*?-->/gs;
let str = `... <!-- My -- comment let str = `... <!-- Мій -- коментар test --> .. <!----> .. `;
alert( str.match(regexp) ); // '<!-- My -- comment \n test -->', '<!---->' alert( str.match(regexp) ); // '<!-- Мій -- коментар \n test -->', '<!---->' ```
An acceptable variant is `pattern:<!--.*?-->` -- the lazy quantifier makes the dot stop right before `match:-->`. We also need to add flag `pattern:s` for the dot to include newlines. Прийнятним є варіант `pattern:<!--.*?-->` -- лінивий квантифікатор зупиняє крапку (будь-який символ, за винятком символу нового рядку) прямо перед `match:-->`. Нам також треба додати прапорець `pattern:s`, аби крапка включала символи нового рядку.
Otherwise multiline comments won't be found: Інакше коментарі на кілька рядків не знаходитимуться:
```js run let regexp = /<!--.*?-->/gs;
let str = `... <!-- My -- comment let str = `... <!-- Мій -- коментар test --> .. <!----> .. `;
alert( str.match(regexp) ); // '<!-- My -- comment \n test -->', '<!---->' alert( str.match(regexp) ); // '<!-- Мій -- коментар \n test -->', '<!---->' ```