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
Let's say we have a string like `+7(903)-123-45-67`and want to find all numbers in it. But unlike before, we are interested not in single digits, but full numbers: `7, 903, 123, 45, 67`.
3
+
Se si ha una stringa come la seguente: `+7(903)-123-45-67`e si vogliono trovare tutti i numeri che contiene ma, diversamente da prima, non siamo interessati alle singole cifre bensì agli interi numeri: `7, 903, 123, 45, 67`.
4
4
5
-
A number is a sequence of 1 or more digits`\d`. To mark how many we need, we need to append a *quantifier*.
5
+
Se definisce numero un sequenza di una o più cifre`\d`, per marcare quanti ne servono si deve aggiungere in coda un *quantificatore*.
6
6
7
-
## Quantity {n}
7
+
## Quantità {n}
8
8
9
-
The simplest quantifier is a number in curly braces:`pattern:{n}`.
9
+
Il quantificatore più semplice è un numero tra parentesi graffe`pattern:{n}`.
10
10
11
-
A quantifier is appended to a character (or a character class, or a `[...]` set etc) and specifies how many we need.
11
+
Un quantificatore si appende a un carattere (o a una classe di caratteri `[...]` un set, ecc..) specificando quante volte questo debba essere ripetuto.
12
+
Si riportano alcune forme avanzate, eccone alcuni esempi:
12
13
13
-
It has a few advanced forms, let's see examples:
14
-
15
-
The exact count: `{5}`
16
-
: `pattern:\d{5}` denotes exactly 5 digits, the same as `pattern:\d\d\d\d\d`.
17
-
18
-
The example below looks for a 5-digit number:
14
+
Il conteggio esatto: `{5}`
15
+
: `pattern:\d{5}` denota esattamente 5 cifre, identico a `pattern:\d\d\d\d\d`.
19
16
17
+
Nell'esempio sottostante si cerca un numero a 5 cifre:
18
+
20
19
```js run
21
-
alert( "I'm 12345 years old".match(/\d{5}/) ); // "12345"
```smart header="To make a regexp more precise, we often need make it more complex"
131
-
We can see one common rule in these examples: the more precise is the regular expression -- the longer and more complex it is.
129
+
```smart header="Per rendere una espressione regolare più precisa, spesso dobbiamo renderla anche più complessa"
130
+
Possiamo vederne una regola comune in questo esempio: più l'espressione regolare è precisa -- più è lunga e complicata.
132
131
133
-
For instance, for HTML tags we could use a simpler regexp: `pattern:<\w+>`.
132
+
Ad esempio, per i tag HTML è possibile usare un'espressione regolare più semplice: `pattern:<\w+>`.
134
133
135
-
...But because `pattern:\w` means any Latin letter or a digit or `'_'`, the regexp also matches non-tags, for instance `match:<_>`. So it's much simpler than `pattern:<[a-z][a-z0-9]*>`, but less reliable.
134
+
...Ma poiché `pattern:\w` intercetta qualsiasi lettera dell'alfabeto latino e il carattere `'_'`, la regexp intercetta anche dei non-tag, come `match:<_>`. Dunque è molto più semplice del pattern `pattern:<[a-z][a-z0-9]*>`, ma anche meno affidabile.
136
135
137
-
Are we ok with `pattern:<\w+>` or we need `pattern:<[a-z][a-z0-9]*>`?
136
+
Basta accontentarsi di `pattern:<\w+>` o è necessario `pattern:<[a-z][a-z0-9]*>`?
138
137
139
-
In real life both variants are acceptable. Depends on how tolerant we can be to "extra" matches and whether it's difficult or not to filter them out by other means.
138
+
La risposta è che nella vita reale entrambi sono accettabili; dipende però dal bilanciamento tra l'avere molte corrispondenze "extra" da filtrare in altri modi rispetto all'avere un'erspressione regolare più complessa.
0 commit comments