Skip to content

Commit 95ded40

Browse files
authored
Merge pull request #318 from marcellosurdi/article/regexp-greedy-and-lazy
Greedy and lazy quantifiers
2 parents 468d705 + d57b833 commit 95ded40

File tree

7 files changed

+122
-122
lines changed

7 files changed

+122
-122
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

2-
The result is: `match:123 4`.
2+
Il risultato è: `match:123 4`.
33

4-
First the lazy `pattern:\d+?` tries to take as little digits as it can, but it has to reach the space, so it takes `match:123`.
4+
Inizialmente il quantificatore lazy `pattern:\d+?` prova a prendere il minor numero di cifre, ma deve raggiungere lo spazio, perciò include `match:123`.
55

6-
Then the second `\d+?` takes only one digit, because that's enough.
6+
Il secondo `\d+?` prende una cifra soltanto perché è sufficiente.

9-regular-expressions/10-regexp-greedy-and-lazy/1-lazy-greedy/task.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# A match for /d+? d+?/
1+
# Individuate la corrispondenza per /d+? d+?/
22

3-
What's the match here?
3+
Quale è la corrispondenza in questo caso?
44

55
```js
66
alert( "123 456".match(/\d+? \d+?/g) ); // ?

9-regular-expressions/10-regexp-greedy-and-lazy/3-find-html-comments/solution.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
We need to find the beginning of the comment `match:<!--`, then everything till the end of `match:-->`.
1+
Abbiamo bisogno di trovare l'inizio del commento `match:<!--`, e dopo tutto quello che c'è fino a `match:-->`.
22

3-
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.
3+
Una variante accettabile è `pattern:<!--.*?-->`, il quantificatore lazy fa sì che la ricerca si fermi prima di `match:-->`. Dobbiamo, inoltre, aggiungere il flag `pattern:s` in modo che il punto includa gli a capo.
44

5-
Otherwise multiline comments won't be found:
5+
In caso contrario i commenti multilinea non verranno trovati:
66

77
```js run
88
let regexp = /<!--.*?-->/gs;

9-regular-expressions/10-regexp-greedy-and-lazy/3-find-html-comments/task.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
# Find HTML comments
1+
# Trovate i commenti HTML
22

3-
Find all HTML comments in the text:
3+
Trovate tutti i commenti HTML nel testo:
44

55
```js
66
let regexp = /your regexp/g;
77

88
let str = `... <!-- My -- comment
9-
test --> .. <!----> ..
9+
test --> .. <!----> ..
1010
`;
1111

1212
alert( str.match(regexp) ); // '<!-- My -- comment \n test -->', '<!---->'

9-regular-expressions/10-regexp-greedy-and-lazy/4-find-html-tags-greedy-lazy/solution.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
The solution is `pattern:<[^<>]+>`.
2+
La soluzione è `pattern:<[^<>]+>`.
33

44
```js run
55
let regexp = /<[^<>]+>/g;
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# Find HTML tags
1+
# Trovate i tag HTML
22

3-
Create a regular expression to find all (opening and closing) HTML tags with their attributes.
3+
Create un'espressione regolare per trovare tutti i tag HTML (di apertura e di chiusura) con i loro attributi.
44

5-
An example of use:
5+
Ecco un esempio d'uso:
66

77
```js run
88
let regexp = /your regexp/g;
@@ -12,4 +12,4 @@ let str = '<> <a href="/"> <input type="radio" checked> <b>';
1212
alert( str.match(regexp) ); // '<a href="/">', '<input type="radio" checked>', '<b>'
1313
```
1414

15-
Here we assume that tag attributes may not contain `<` and `>` (inside quotes too), that simplifies things a bit.
15+
In questo caso presumiamo che gli attributi dei tag non contengano `<` e `>` dentro i doppi apici per semplificare l'esercizio.

9-regular-expressions/10-regexp-greedy-and-lazy/article.md

Lines changed: 106 additions & 106 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)