Skip to content

Commit 3609834

Browse files
committed
Update 9-regular-expressions\10-regexp-greedy-and-lazy\article.md
1 parent ab6d78a commit 3609834

File tree

1 file changed

+6
-6
lines changed
  • 9-regular-expressions/10-regexp-greedy-and-lazy

1 file changed

+6
-6
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Modalità greedy e lazy dei quantificatori
22

3-
I quantificatori sono molto semplici a prima vista, ma in realtà possono essere complicati.
3+
I quantificatori sono molto semplici a prima vista, ma in realtà possono riverlarsi complicati.
44

55
Dovremmo comprendere appieno come funziona la ricerca se intendiamo cercare qualcosa di più complesso di `pattern:/\d+/`.
66

7-
Prendiamo ad esempio la seguente attività.
7+
Prendiamo ad esempio la seguente esercitazione.
88

99
Abbiamo bisogno di rimpiazzare tutti i doppi apici `"..."` in un testo con le virgolette basse: `«...»`, che sono preferite nella tipografia di molti paesi.
1010

@@ -54,15 +54,15 @@ Questa procedura generica non ci spiega con evidenza perché l'espressione regol
5454

5555
![](witch_greedy2.svg)
5656

57-
3. Then the dot repeats because of the quantifier `pattern:.+`. The regular expression engine adds to the match one character after another.
57+
3. Successivamente il punto trova ulteriori riscontri per via del quantificatore `pattern:.+`. Il motore dell'espressione regolare aggiunge un carattere dopo l'altro.
5858

59-
...Until when? All characters match the dot, so it only stops when it reaches the end of the string:
59+
...Fino a quando? Tutti i caratteri corrispondono al punto, quindi si ferma solo quando raggiunge la fine della stringa:
6060

6161
![](witch_greedy3.svg)
6262

63-
4. Now the engine finished repeating `pattern:.+` and tries to find the next character of the pattern. It's the quote `pattern:"`. But there's a problem: the string has finished, there are no more characters!
63+
4. A questo punto il motore cessa di ripetere `pattern:.+` e prova a trovare il prossimo carattere del pattern. Si tratta del doppio apice `pattern:"`. C'è un problema però: la stringa è finita, non ci sono più caratteri!
6464

65-
The regular expression engine understands that it took too many `pattern:.+` and starts to *backtrack*.
65+
Il motore dell'espressione regolare capisce che ha preso troppi caratteri per `pattern:.+` e comincia a *retrocedere*.
6666

6767
In other words, it shortens the match for the quantifier by one character:
6868

0 commit comments

Comments
 (0)