diff --git a/9-regular-expressions/11-regexp-groups/01-test-mac/solution.md b/9-regular-expressions/11-regexp-groups/01-test-mac/solution.md index 26f7888f7..7f9b7357c 100644 --- a/9-regular-expressions/11-regexp-groups/01-test-mac/solution.md +++ b/9-regular-expressions/11-regexp-groups/01-test-mac/solution.md @@ -1,21 +1,21 @@ -A two-digit hex number is `pattern:[0-9a-f]{2}` (assuming the flag `pattern:i` is set). +Un numero esadecimale a due cifre è `pattern:[0-9a-f]{2}` (dando per scontato che il flag `pattern:i` sia presente). -We need that number `NN`, and then `:NN` repeated 5 times (more numbers); +Dobbiamo trovare quel numero `NN`, seguito da `:NN` ripetuto 5 volte. -The regexp is: `pattern:[0-9a-f]{2}(:[0-9a-f]{2}){5}` +L'espressione regolare è: `pattern:[0-9a-f]{2}(:[0-9a-f]{2}){5}` -Now let's show that the match should capture all the text: start at the beginning and end at the end. That's done by wrapping the pattern in `pattern:^...$`. +Osserviamo, a questo punto, che la corrispondenza dovrebbe catturare tutto il testo: dall'inizio alla fine. A questo scopo racchiudiamo il pattern all'interno di `pattern:^...$`. -Finally: +Quindi: ```js run let regexp = /^[0-9a-fA-F]{2}(:[0-9a-fA-F]{2}){5}$/i; alert( regexp.test('01:32:54:67:89:AB') ); // true -alert( regexp.test('0132546789AB') ); // false (no colons) +alert( regexp.test('0132546789AB') ); // false (non ci sono i due punti) -alert( regexp.test('01:32:54:67:89') ); // false (5 numbers, need 6) +alert( regexp.test('01:32:54:67:89') ); // false (5 numeri invece di 6) -alert( regexp.test('01:32:54:67:89:ZZ') ) // false (ZZ in the end) +alert( regexp.test('01:32:54:67:89:ZZ') ) // false (ZZ alla fine) ``` diff --git a/9-regular-expressions/11-regexp-groups/01-test-mac/task.md b/9-regular-expressions/11-regexp-groups/01-test-mac/task.md index 1ef06fcf9..7cb0fcabe 100644 --- a/9-regular-expressions/11-regexp-groups/01-test-mac/task.md +++ b/9-regular-expressions/11-regexp-groups/01-test-mac/task.md @@ -1,4 +1,4 @@ -# Controllo MAC-address +# Verificate il MAC-address Il [MAC-address](https://it.wikipedia.org/wiki/Indirizzo_MAC) di un'interfaccia di rete è composto da 6 coppie di cifre esadecimali separati dai due punti. diff --git a/9-regular-expressions/11-regexp-groups/02-find-webcolor-3-or-6/solution.md b/9-regular-expressions/11-regexp-groups/02-find-webcolor-3-or-6/solution.md index 0806dc4fd..dbf6234e8 100644 --- a/9-regular-expressions/11-regexp-groups/02-find-webcolor-3-or-6/solution.md +++ b/9-regular-expressions/11-regexp-groups/02-find-webcolor-3-or-6/solution.md @@ -1,12 +1,12 @@ -A regexp to search 3-digit color `#abc`: `pattern:/#[a-f0-9]{3}/i`. +L'espressione regolare per cercare il codice di un colore di 3 cifre `#abc` è : `pattern:/#[a-f0-9]{3}/i`. -We can add exactly 3 more optional hex digits. We don't need more or less. The color has either 3 or 6 digits. +Possiamo aggiungere esattamente 3 ulteriori cifre esadecimali opzionali. Non abbiamo bisogno di altro. Il codice di un colore è composto da 3 o 6 cifre. -Let's use the quantifier `pattern:{1,2}` for that: we'll have `pattern:/#([a-f0-9]{3}){1,2}/i`. +Usiamo il quantificatore `pattern:{1,2}` a questo scopo: avremo `pattern:/#([a-f0-9]{3}){1,2}/i`. -Here the pattern `pattern:[a-f0-9]{3}` is enclosed in parentheses to apply the quantifier `pattern:{1,2}`. +In questo caso il pattern `pattern:[a-f0-9]{3}` è racchiuso tra parentesi per applicare ad esso il quantificatore `pattern:{1,2}`. -In action: +Eccolo in azione: ```js run let regexp = /#([a-f0-9]{3}){1,2}/gi; @@ -16,7 +16,7 @@ let str = "color: #3f3; background-color: #AA00ef; and: #abcd"; alert( str.match(regexp) ); // #3f3 #AA00ef #abc ``` -There's a minor problem here: the pattern found `match:#abc` in `subject:#abcd`. To prevent that we can add `pattern:\b` to the end: +C'è un piccolo problema adesso: il pattern `match:#abc` trovato in `subject:#abcd`. Per evitarlo possiamo aggiungere `pattern:\b` alla fine: ```js run let regexp = /#([a-f0-9]{3}){1,2}\b/gi; diff --git a/9-regular-expressions/11-regexp-groups/02-find-webcolor-3-or-6/task.md b/9-regular-expressions/11-regexp-groups/02-find-webcolor-3-or-6/task.md index 09108484a..2f5f821b8 100644 --- a/9-regular-expressions/11-regexp-groups/02-find-webcolor-3-or-6/task.md +++ b/9-regular-expressions/11-regexp-groups/02-find-webcolor-3-or-6/task.md @@ -1,8 +1,8 @@ -# Find color in the format #abc or #abcdef +# Trovate un colore nel formato #abc o #abcdef -Write a RegExp that matches colors in the format `#abc` or `#abcdef`. That is: `#` followed by 3 or 6 hexadecimal digits. +Scrivete un'espressione regolare che trovi i colori nel formato `#abc` o `#abcdef`. In altre parole: `#` seguito da 3 o 6 cifre esadecimali. -Usage example: +Esempio d'uso: ```js let regexp = /your regexp/g; @@ -11,4 +11,4 @@ let str = "color: #3f3; background-color: #AA00ef; and: #abcd"; alert( str.match(regexp) ); // #3f3 #AA00ef ``` -P.S. This should be exactly 3 or 6 hex digits. Values with 4 digits, such as `#abcd`, should not match. +P.S. Dovrebbe trovare esattamente 3 o 6 cifre esadecimali. I valori con 4 cifre, come `#abcd`, non dovrebbero dar luogo a corrispondenza. diff --git a/9-regular-expressions/11-regexp-groups/03-find-decimal-numbers/solution.md b/9-regular-expressions/11-regexp-groups/03-find-decimal-numbers/solution.md index 813d619ef..48c9c2a66 100644 --- a/9-regular-expressions/11-regexp-groups/03-find-decimal-numbers/solution.md +++ b/9-regular-expressions/11-regexp-groups/03-find-decimal-numbers/solution.md @@ -1,6 +1,6 @@ -A positive number with an optional decimal part is: `pattern:\d+(\.\d+)?`. +Un numero positivo con una parte decimale opzionale è: `pattern:\d+(\.\d+)?`. -Let's add the optional `pattern:-` in the beginning: +Aggiungiamo all'inizio il segno meno facoltativo `pattern:-`: ```js run let regexp = /-?\d+(\.\d+)?/g; diff --git a/9-regular-expressions/11-regexp-groups/03-find-decimal-numbers/task.md b/9-regular-expressions/11-regexp-groups/03-find-decimal-numbers/task.md index 4f5a73fff..18715d187 100644 --- a/9-regular-expressions/11-regexp-groups/03-find-decimal-numbers/task.md +++ b/9-regular-expressions/11-regexp-groups/03-find-decimal-numbers/task.md @@ -1,8 +1,8 @@ -# Find all numbers +# Trovate tutti i numeri -Write a regexp that looks for all decimal numbers including integer ones, with the floating point and negative ones. +Scrivete un'espressione regolare che cerchi tutti i numeri decimali e interi, con virgola mobile e negativi. -An example of use: +Un esempio d'uso: ```js let regexp = /your regexp/g; diff --git a/9-regular-expressions/11-regexp-groups/04-parse-expression/solution.md b/9-regular-expressions/11-regexp-groups/04-parse-expression/solution.md index ac67519bb..81282e8b3 100644 --- a/9-regular-expressions/11-regexp-groups/04-parse-expression/solution.md +++ b/9-regular-expressions/11-regexp-groups/04-parse-expression/solution.md @@ -1,21 +1,21 @@ -A regexp for a number is: `pattern:-?\d+(\.\d+)?`. We created it in the previous task. +L'espressione regolare per un numero è: `pattern:-?\d+(\.\d+)?`. L'abbiamo creata nell'esercizione precedente. -An operator is `pattern:[-+*/]`. The hyphen `pattern:-` goes first in the square brackets, because in the middle it would mean a character range, while we just want a character `-`. +Per trovare un operatore usiamo `pattern:[-+*/]`. Il trattino `pattern:-` va posto all'inizio nelle parentesi quadre, in mezzo significherebbe un intervallo di caratteri, mentre noi vogliamo soltanto il carattere `-`. -The slash `/` should be escaped inside a JavaScript regexp `pattern:/.../`, we'll do that later. +Dovremmo fare l'escape dello slash `/` dentro una regexp JavaScript `pattern:/.../`, lo faremo dopo. -We need a number, an operator, and then another number. And optional spaces between them. +Abbiamo bisogno di un numero, un operatore, e quindi un altro numero. Tra di essi ci possono essere spazi opzionali. -The full regular expression: `pattern:-?\d+(\.\d+)?\s*[-+*/]\s*-?\d+(\.\d+)?`. +Ecco l'intera espressione regolare: `pattern:-?\d+(\.\d+)?\s*[-+*/]\s*-?\d+(\.\d+)?`. -It has 3 parts, with `pattern:\s*` between them: -1. `pattern:-?\d+(\.\d+)?` - the first number, -1. `pattern:[-+*/]` - the operator, -1. `pattern:-?\d+(\.\d+)?` - the second number. +Questa consta di 3 parti, intervallate da `pattern:\s*`: +1. `pattern:-?\d+(\.\d+)?` - il primo numero, +1. `pattern:[-+*/]` - l'operatore, +1. `pattern:-?\d+(\.\d+)?` - il secondo numero. -To make each of these parts a separate element of the result array, let's enclose them in parentheses: `pattern:(-?\d+(\.\d+)?)\s*([-+*/])\s*(-?\d+(\.\d+)?)`. +Per rendere ciascuna di queste parti un elemento separato dell'array di risultati le racchiudiamo tra parentesi: `pattern:(-?\d+(\.\d+)?)\s*([-+*/])\s*(-?\d+(\.\d+)?)`. -In action: +In azione: ```js run let regexp = /(-?\d+(\.\d+)?)\s*([-+*\/])\s*(-?\d+(\.\d+)?)/; @@ -23,22 +23,22 @@ let regexp = /(-?\d+(\.\d+)?)\s*([-+*\/])\s*(-?\d+(\.\d+)?)/; alert( "1.2 + 12".match(regexp) ); ``` -The result includes: +Il risultato include: -- `result[0] == "1.2 + 12"` (full match) -- `result[1] == "1.2"` (first group `(-?\d+(\.\d+)?)` -- the first number, including the decimal part) -- `result[2] == ".2"` (second group`(\.\d+)?` -- the first decimal part) -- `result[3] == "+"` (third group `([-+*\/])` -- the operator) -- `result[4] == "12"` (forth group `(-?\d+(\.\d+)?)` -- the second number) -- `result[5] == undefined` (fifth group `(\.\d+)?` -- the last decimal part is absent, so it's undefined) +- `result[0] == "1.2 + 12"` (l'intera corrispondenza) +- `result[1] == "1.2"` (il primo gruppo `(-?\d+(\.\d+)?)`, il primo numero compresa la parte decimale) +- `result[2] == ".2"` (il secondo gruppo`(\.\d+)?`, la prima parte decimale) +- `result[3] == "+"` (il terzo gruppo `([-+*\/])`, l'operatore) +- `result[4] == "12"` (il quarto gruppo `(-?\d+(\.\d+)?)`, il secondo numero) +- `result[5] == undefined` (il quinto gruppo `(\.\d+)?`, l'ultima parte decimale è assente, quindi equivale ad undefined) -We only want the numbers and the operator, without the full match or the decimal parts, so let's "clean" the result a bit. +Il nostro scopo è ottenere i numeri e l'operatore, senza l'intera corrispondenza o le parti decimali, quindi "puliamo" un po' il risultato. -The full match (the arrays first item) can be removed by shifting the array `result.shift()`. +L'intera corrispondenza (il primo elemento dell'array) possiamo rimuoverla con `result.shift()`. -Groups that contain decimal parts (number 2 and 4) `pattern:(.\d+)` can be excluded by adding `pattern:?:` to the beginning: `pattern:(?:\.\d+)?`. +I gruppi che contengono le parti decimali (gli elementi 2 e 4) `pattern:(.\d+)` li escludiamo aggiungendo `pattern:?:` all'inizio: `pattern:(?:\.\d+)?`. -The final solution: +La soluzione finale: ```js run function parse(expr) { diff --git a/9-regular-expressions/11-regexp-groups/04-parse-expression/task.md b/9-regular-expressions/11-regexp-groups/04-parse-expression/task.md index 8b54d4683..b166834a9 100644 --- a/9-regular-expressions/11-regexp-groups/04-parse-expression/task.md +++ b/9-regular-expressions/11-regexp-groups/04-parse-expression/task.md @@ -1,23 +1,23 @@ -# Parse an expression +# Analizzate un'espressione -An arithmetical expression consists of 2 numbers and an operator between them, for instance: +Un'espressione aritmetica consiste in 2 numeri e un operatore tra di essi, ad esempio: - `1 + 2` - `1.2 * 3.4` - `-3 / -6` - `-2 - 2` -The operator is one of: `"+"`, `"-"`, `"*"` or `"/"`. +L'operatore è uno fra: `"+"`, `"-"`, `"*"` o `"/"`. -There may be extra spaces at the beginning, at the end or between the parts. +Potrebbero esserci ulteriori spazi all'inizio, alla fine o tra gli elementi. -Create a function `parse(expr)` that takes an expression and returns an array of 3 items: +Create una funzione `parse(expr)` che riceva un'espressione e restituisca un array di 3 elementi: -1. The first number. -2. The operator. -3. The second number. +1. Il primo numero. +2. L'operatore. +3. Il secondo numero. -For example: +Ad esempio: ```js let [a, op, b] = parse("1.2 * 3.4"); diff --git a/9-regular-expressions/11-regexp-groups/article.md b/9-regular-expressions/11-regexp-groups/article.md index e0ef00bd3..32c468ab4 100644 --- a/9-regular-expressions/11-regexp-groups/article.md +++ b/9-regular-expressions/11-regexp-groups/article.md @@ -1,31 +1,31 @@ -# Capturing groups +# I gruppi di acquisizione (capturing group) -A part of a pattern can be enclosed in parentheses `pattern:(...)`. This is called a "capturing group". +Una parte del pattern può essere racchiusa tra parentesi `pattern:(...)`, diventando così un "gruppo di acquisizione" (capturing group). -That has two effects: +Ciò comporta due conseguenze: -1. It allows to get a part of the match as a separate item in the result array. -2. If we put a quantifier after the parentheses, it applies to the parentheses as a whole. +1. Possiamo acquisire una parte della corrispondenza come elemento separato all'interno di un array di risultati. +2. Se poniamo un quantificatore dopo le parentesi, questo si applica all'intero gruppo di acquisizione. -## Examples +## Esempi -Let's see how parentheses work in examples. +Vediamo come operano le parentesi attraverso degli esempi. -### Example: gogogo +### Esempio: gogogo -Without parentheses, the pattern `pattern:go+` means `subject:g` character, followed by `subject:o` repeated one or more times. For instance, `match:goooo` or `match:gooooooooo`. +Senza parentesi, il pattern `pattern:go+` significa: il carattere `subject:g` seguito da `subject:o` ripetuto una o più volte. Per esempio `match:goooo` o `match:gooooooooo`. -Parentheses group characters together, so `pattern:(go)+` means `match:go`, `match:gogo`, `match:gogogo` and so on. +Le parentesi raggruppano i caratteri, pertanto `pattern:(go)+` significa `match:go`, `match:gogo`, `match:gogogo` e così via. ```js run alert( 'Gogogo now!'.match(/(go)+/ig) ); // "Gogogo" ``` -### Example: domain +### Esempio: dominio -Let's make something more complex -- a regular expression to search for a website domain. +Facciamo un esempio un po' più complesso, un'espressione regolare per cercare il dominio di un sito. -For example: +Per esempio: ``` mail.com @@ -33,9 +33,9 @@ users.mail.com smith.users.mail.com ``` -As we can see, a domain consists of repeated words, a dot after each one except the last one. +Come possiamo vedere, un dominio consiste in parole ripetute, un punto segue ciascuna parola tranne l'ultima. -In regular expressions that's `pattern:(\w+\.)+\w+`: +Tradotto in un'espressione regolare diventa `pattern:(\w+\.)+\w+`: ```js run let regexp = /(\w+\.)+\w+/g; @@ -43,17 +43,17 @@ let regexp = /(\w+\.)+\w+/g; alert( "site.com my.site.com".match(regexp) ); // site.com,my.site.com ``` -The search works, but the pattern can't match a domain with a hyphen, e.g. `my-site.com`, because the hyphen does not belong to class `pattern:\w`. +La ricerca funziona, ma il pattern non trova riscontro con domini contenenti un trattino, es. `my-site.com`, perché il trattino non appartiene alla classe `pattern:\w`. -We can fix it by replacing `pattern:\w` with `pattern:[\w-]` in every word except the last one: `pattern:([\w-]+\.)+\w+`. +Possiamo correggere il tiro rimpiazzando `pattern:\w` con `pattern:[\w-]` in ogni parola eccetto l'ultima: `pattern:([\w-]+\.)+\w+`. -### Example: email +### Esempio: email -The previous example can be extended. We can create a regular expression for emails based on it. +Il precedente esempio può essere esteso. A partire da questo possiamo creare un'espressione regolare per le email. -The email format is: `name@domain`. Any word can be the name, hyphens and dots are allowed. In regular expressions that's `pattern:[-.\w]+`. +Il formato delle email è: `name@domain`. Qualsiasi parola può essere "name", sono consentiti trattini e punti. L'espressione regolare diventa `pattern:[-.\w]+`. -The pattern: +Ecco il pattern: ```js run let regexp = /[-.\w]+@([\w-]+\.)+[\w-]+/g; @@ -61,24 +61,24 @@ let regexp = /[-.\w]+@([\w-]+\.)+[\w-]+/g; alert("my@mail.com @ his@site.com.uk".match(regexp)); // my@mail.com, his@site.com.uk ``` -That regexp is not perfect, but mostly works and helps to fix accidental mistypes. The only truly reliable check for an email can only be done by sending a letter. +Questa regexp non è perfetta, ma per lo più funziona e aiuta a correggere errori di battitura accidentali. L'unica verifica davvero efficace per un'email può essere fatta soltanto inviandone una. -## Parentheses contents in the match +## I contenuti tra parentesi nella corrispondenza -Parentheses are numbered from left to right. The search engine memorizes the content matched by each of them and allows to get it in the result. +I gruppi tra parentesi sono numerati da sinistra verso destra. Il motore di ricerca memorizza il contenuto associato a ciascuno di essi e consente di recuperarlo nel risultato. -The method `str.match(regexp)`, if `regexp` has no flag `g`, looks for the first match and returns it as an array: +Il metodo `str.match(regexp)`, se `regexp` non ha il flag `g`, cerca la prima corrispondenza e la restituisce in un array: -1. At index `0`: the full match. -2. At index `1`: the contents of the first parentheses. -3. At index `2`: the contents of the second parentheses. -4. ...and so on... +1. Nell'indice `0`: l'intera corrispondenza. +2. Nell'indice `1`: il contenuto del primo gruppo tra parentesi. +3. Nell'indice `2`: il contenuto del secondo. +4. ...e così via... -For instance, we'd like to find HTML tags `pattern:<.*?>`, and process them. It would be convenient to have tag content (what's inside the angles), in a separate variable. +Ad esempio se volessimo trovare i tag HTML `pattern:<.*?>` per elaborarli, sarebbe conveniente averne il contenuto (ciò che è all'interno delle parentesi uncinate) in una variabile separata. -Let's wrap the inner content into parentheses, like this: `pattern:<(.*?)>`. +Racchiudiamo il contenuto tra parentesi, in questo modo: `pattern:<(.*?)>`. -Now we'll get both the tag as a whole `match:
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: