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
Copy file name to clipboardExpand all lines: 9-regular-expressions/12-regexp-backreferences/article.md
+10-10Lines changed: 10 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,7 @@ Per comprendere chiaramente perché sia utile, consideriamo l'esercitazione segu
10
10
11
11
Dobbiamo trovare le stringhe tra apici: sia quelli singoli `subject:'...'` sia quelli doppi `subject:"..."`, entrambi devono dare luogo a riscontro.
12
12
13
-
Come trovarle?
13
+
Come trovarli?
14
14
15
15
Potremmo mettere i due tipi di apici all'interno di parentesi quadre: `pattern:['"](.*?)['"]`, ma in questo modo troveremmo anche le stringhe con apici misti come `match:"...'` e `match:'..."`. Questo porterebbe a risultati inesatti quando un tipo di apice compare tra due dell'altro tipo, come nella stringa `subject:"She's the one!"`:
16
16
@@ -39,27 +39,27 @@ let regexp = /(['"])(.*?)\1/g;
39
39
alert( str.match(regexp) ); // "She's the one!"
40
40
```
41
41
42
-
Ora funziona! The regular expression engine finds the first quote `pattern:(['"])`and memorizes its content. That's the first capturing group.
42
+
Ora funziona! L'interprete dell'espressione regolare trova il primo apice `pattern:(['"])`e lo memorizza. Questo è il primo gruppo di acquisizione.
43
43
44
-
Further in the pattern `pattern:\1`means "find the same text as in the first group", exactly the same quote in our case.
44
+
Più avanti nel pattern `pattern:\1`significa "trova lo stesso testo del primo gruppo", nel nostro caso esattamente lo stesso apice.
45
45
46
-
Similar to that, `pattern:\2`would mean the contents of the second group, `pattern:\3`- the 3rd group, and so on.
46
+
Similmente `pattern:\2`indicherebbe il contenuto del secondo gruppo, `pattern:\3`quello del terzo gruppo, e così via.
47
47
48
48
```smart
49
-
If we use `?:` in the group, then we can't reference it. Groups that are excluded from capturing `(?:...)` are not memorized by the engine.
49
+
Se nel gruppo usiamo `?:` non sarà possibile riferirsi ad esso. I gruppi esclusi dall'acquisizione `(?:...)` non sono memorizzati dall'interprete.
50
50
```
51
51
52
-
```warn header="Don't mess up: in the pattern `pattern:\1`, in the replacement:`pattern:$1`"
53
-
In the replacement string we use a dollar sign: `pattern:$1`, while in the pattern - a backslash `pattern:\1`.
52
+
```warn header="Non fare confusione: nel pattern `pattern:\1`, nelle sostituzioni`pattern:$1`"
53
+
Nelle sostituzioni di stringa si adopera il segno di dollaro: `pattern:$1`, mentre nel contesto di un pattern il backslash `pattern:\1`.
54
54
```
55
55
56
56
## Riferimento all'indietro per nome: `\k<name>`
57
57
58
-
If a regexp has many parentheses, it's convenient to give them names.
58
+
Se un'espressione regolare ha tante parentesi, è opportuno dare loro dei nomi.
59
59
60
-
To reference a named group we can use `pattern:\k<name>`.
60
+
Per riferirsi ad un gruppo nominato si usa `pattern:\k<name>`.
61
61
62
-
In the example below the group with quotes is named `pattern:?<quote>`, so the backreference is `pattern:\k<quote>`:
62
+
Nell'esempio sotto il gruppo con gli apici è nominato `pattern:?<quote>`, pertanto il riferimento è `pattern:\k<quote>`:
0 commit comments