Skip to content

Commit 529de12

Browse files
committed
Start translating 9-regular-expressions\10-regexp-greedy-and-lazy\article.md
1 parent 67ccf23 commit 529de12

File tree

1 file changed

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

1 file changed

+14
-14
lines changed

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
# Greedy and lazy quantifiers
1+
# Modalità greedy e lazy dei quantificatori
22

3-
Quantifiers are very simple from the first sight, but in fact they can be tricky.
3+
I quantificatori sono molto semplici a prima vista, ma in realtà possono essere complicati.
44

5-
We should understand how the search works very well if we plan to look for something more complex than `pattern:/\d+/`.
5+
Dovremmo comprendere appieno come funziona la ricerca se intendiamo cercare qualcosa di più complesso di `pattern:/\d+/`.
66

7-
Let's take the following task as an example.
7+
Prendiamo ad esempio la seguente attività.
88

9-
We have a text and need to replace all quotes `"..."` with guillemet marks: `«...»`. They are preferred for typography in many countries.
9+
Abbiamo bisogno di rimpiazzare tutti i doppi apici `"..."` in un testo con le virgolette basse: `«...»`, che sono preferite nella tipografia di molti paesi.
1010

11-
For instance: `"Hello, world"` should become `«Hello, world»`. There exist other quotes, such as `„Witam, świat!”` (Polish) or `「你好,世界」` (Chinese), but for our task let's choose `«...»`.
11+
Ad esempio: `"Hello, world"` dovrebbe diventare `«Hello, world»`. Esistono altre virgolette, come `„Witam, świat!”` (in Polonia) o `「你好,世界」` (in Cina). In questo caso, tuttavia, scegliamo `«...»`.
1212

13-
The first thing to do is to locate quoted strings, and then we can replace them.
13+
Innanzitutto dobbiamo individuare le stringhe tra doppi apici per poi sostituirli.
1414

15-
A regular expression like `pattern:/".+"/g` (a quote, then something, then the other quote) may seem like a good fit, but it isn't!
15+
Un'espressione regolare come `pattern:/".+"/g` (una stringa di lunghezza variabile racchiusa da doppi apici) può sembrare efficace, ma non lo è!
1616

17-
Let's try it:
17+
Verifichiamo:
1818

1919
```js run
2020
let regexp = /".+"/g;
@@ -24,13 +24,13 @@ let str = 'a "witch" and her "broom" is one';
2424
alert( str.match(regexp) ); // "witch" and her "broom"
2525
```
2626

27-
...We can see that it works not as intended!
27+
...Non funziona come desideravamo!
2828

29-
Instead of finding two matches `match:"witch"` and `match:"broom"`, it finds one: `match:"witch" and her "broom"`.
29+
Invece di trovare i due riscontri `match:"witch"` e `match:"broom"`, ne trova solo uno: `match:"witch" and her "broom"`.
3030

31-
That can be described as "greediness is the cause of all evil".
31+
Questo fenomeno può essere descritto così: "l'avidità è la causa di tutti i mali".
3232

33-
## Greedy search
33+
## La ricerca in modalità greedy (avida)
3434

3535
To find a match, the regular expression engine uses the following algorithm:
3636

@@ -288,7 +288,7 @@ alert( str1.match(regexp) ); // null, no matches, that's correct
288288
alert( str2.match(regexp) ); // <a href="link1" class="doc">, <a href="link2" class="doc">
289289
```
290290

291-
## Summary
291+
## Riepilogo
292292

293293
Quantifiers have two modes of work:
294294

0 commit comments

Comments
 (0)