From c7a8aee5cec5946345dbf501d82ce704802d58e2 Mon Sep 17 00:00:00 2001 From: idrusma Date: Thu, 3 Jun 2021 11:36:19 +0200 Subject: [PATCH 1/7] Update 9-regular-expressions\14-regexp-lookahead-lookbehind --- .../14-regexp-lookahead-lookbehind/article.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/9-regular-expressions/14-regexp-lookahead-lookbehind/article.md b/9-regular-expressions/14-regexp-lookahead-lookbehind/article.md index 04cca7c86..ff2329991 100644 --- a/9-regular-expressions/14-regexp-lookahead-lookbehind/article.md +++ b/9-regular-expressions/14-regexp-lookahead-lookbehind/article.md @@ -1,6 +1,6 @@ -# Lookahead and lookbehind +# Lookahead e lookbehind -Sometimes we need to find only those matches for a pattern that are followed or preceded by another pattern. +Talvolta abbiamo bisogno di trovare soltanto quei riscontri per un pattern che sono seguiti o preceduti da un altro pattern. There's a special syntax for that, called "lookahead" and "lookbehind", together referred to as "lookaround". From 1057dbe43a5c8efdbe3fe4f779b78ba58a9ef2a9 Mon Sep 17 00:00:00 2001 From: Marcello Date: Thu, 3 Jun 2021 16:13:07 +0200 Subject: [PATCH 2/7] Update 9-regular-expressions\14-regexp-lookahead-lookbehind --- .../14-regexp-lookahead-lookbehind/article.md | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/9-regular-expressions/14-regexp-lookahead-lookbehind/article.md b/9-regular-expressions/14-regexp-lookahead-lookbehind/article.md index ff2329991..fcccdbda6 100644 --- a/9-regular-expressions/14-regexp-lookahead-lookbehind/article.md +++ b/9-regular-expressions/14-regexp-lookahead-lookbehind/article.md @@ -2,32 +2,32 @@ Talvolta abbiamo bisogno di trovare soltanto quei riscontri per un pattern che sono seguiti o preceduti da un altro pattern. -There's a special syntax for that, called "lookahead" and "lookbehind", together referred to as "lookaround". +Esiste a questo scopo una sintassi speciale denominata "lookahead" e "lookbehind", indicata complessivamente con il termine "lookaround". -For the start, let's find the price from the string like `subject:1 turkey costs 30€`. That is: a number, followed by `subject:€` sign. +Per cominciare troviamo il prezzo in una stringa come `subject:1 turkey costs 30€`. In parole semplici: un numero seguito dal simbolo di valuta `subject:€`. ## Lookahead -The syntax is: `pattern:X(?=Y)`, it means "look for `pattern:X`, but match only if followed by `pattern:Y`". There may be any pattern instead of `pattern:X` and `pattern:Y`. +La sintassi è: `pattern:X(?=Y)`, che significa "cerca `pattern:X`, ma trova la corrispondenza solo se seguita da `pattern:Y`". Possiamo sostituire `pattern:X` e `pattern:Y` con un pattern qualsiasi. -For an integer number followed by `subject:€`, the regexp will be `pattern:\d+(?=€)`: +Per un numero intero seguito da `subject:€`, la regexp sarà `pattern:\d+(?=€)`: ```js run let str = "1 turkey costs 30€"; -alert( str.match(/\d+(?=€)/) ); // 30, the number 1 is ignored, as it's not followed by € +alert( str.match(/\d+(?=€)/) ); // 30, viene ignorato il numero 1 in quanto non seguito da € ``` -Please note: the lookahead is merely a test, the contents of the parentheses `pattern:(?=...)` is not included in the result `match:30`. +Si noti che la parte lookahead è solo un test e pertanto il contenuto tra parentesi `pattern:(?=...)` non è incluso nel risultato `match:30`. -When we look for `pattern:X(?=Y)`, the regular expression engine finds `pattern:X` and then checks if there's `pattern:Y` immediately after it. If it's not so, then the potential match is skipped, and the search continues. +Quando cerchiamo `pattern:X(?=Y)` l'interprete dell'espressione regolare trova `pattern:X` e successivamente verifica anche la presenza di `pattern:Y` subito dopo di esso. In caso contrario la corrispondenza potenziale viene scartata e la ricerca prosegue. -More complex tests are possible, e.g. `pattern:X(?=Y)(?=Z)` means: +Sono possibili test più complessi, ad esempio `pattern:X(?=Y)(?=Z)` significa: -1. Find `pattern:X`. -2. Check if `pattern:Y` is immediately after `pattern:X` (skip if isn't). -3. Check if `pattern:Z` is also immediately after `pattern:X` (skip if isn't). -4. If both tests passed, then the `pattern:X` is a match, otherwise continue searching. +1. Trova `pattern:X`. +2. Verifica se `pattern:Y` sia subito dopo `pattern:X` (non proseguire in caso contrario). +3. Verifica se `pattern:Z` sia anch'esso dopo `pattern:X` (non proseguire in caso contrario). +4. Se entrambi i test trovano riscontro considera `pattern:X` una corrispondenza, diversamente continua la ricerca. In other words, such pattern means that we're looking for `pattern:X` followed by `pattern:Y` and `pattern:Z` at the same time. @@ -110,7 +110,7 @@ let regexp = /(?<=(\$|£))\d+/; alert( str.match(regexp) ); // 30, $ ``` -## Summary +## Riepilogo Lookahead and lookbehind (commonly referred to as "lookaround") are useful when we'd like to match something depending on the context before/after it. From 8df25e8d7c6e819d5d08af7da9ef5ae7a577d6b7 Mon Sep 17 00:00:00 2001 From: Marcello Date: Sat, 5 Jun 2021 13:18:50 +0200 Subject: [PATCH 3/7] Update 9-regular-expressions\14-regexp-lookahead-lookbehind --- .../14-regexp-lookahead-lookbehind/article.md | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/9-regular-expressions/14-regexp-lookahead-lookbehind/article.md b/9-regular-expressions/14-regexp-lookahead-lookbehind/article.md index fcccdbda6..093ae6502 100644 --- a/9-regular-expressions/14-regexp-lookahead-lookbehind/article.md +++ b/9-regular-expressions/14-regexp-lookahead-lookbehind/article.md @@ -29,11 +29,11 @@ Sono possibili test più complessi, ad esempio `pattern:X(?=Y)(?=Z)` significa: 3. Verifica se `pattern:Z` sia anch'esso dopo `pattern:X` (non proseguire in caso contrario). 4. Se entrambi i test trovano riscontro considera `pattern:X` una corrispondenza, diversamente continua la ricerca. -In other words, such pattern means that we're looking for `pattern:X` followed by `pattern:Y` and `pattern:Z` at the same time. +In altre parole, questo pattern significa che stiamo cercando `pattern:X` seguito sia da `pattern:Y` sia da `pattern:Z`. -That's only possible if patterns `pattern:Y` and `pattern:Z` aren't mutually exclusive. +Il che è possibile solo se i pattern `pattern:Y` e `pattern:Z` non si escludono a vicenda. -For example, `pattern:\d+(?=\s)(?=.*30)` looks for `pattern:\d+` that is followed by a space `pattern:(?=\s)`, and there's `30` somewhere after it `pattern:(?=.*30)`: +Per esempio, `pattern:\d+(?=\s)(?=.*30)` cerca `pattern:\d+` seguito da uno spazio `pattern:(?=\s)`, e poi c'è `30` da qualche parte dopo di esso `pattern:(?=.*30)`: ```js run let str = "1 turkey costs 30€"; @@ -41,50 +41,50 @@ let str = "1 turkey costs 30€"; alert( str.match(/\d+(?=\s)(?=.*30)/) ); // 1 ``` -In our string that exactly matches the number `1`. +Nella nostra stringa trova esatta corrispondenza nel numero `1`. -## Negative lookahead +## Lookahead negativo -Let's say that we want a quantity instead, not a price from the same string. That's a number `pattern:\d+`, NOT followed by `subject:€`. +Supponiamo invece di volere nella stessa stringa solo la quantità, non il prezzo. Quindi il numero `pattern:\d+`, NON seguito da `subject:€`. -For that, a negative lookahead can be applied. +A questo scopo può essere applicato un lookahead negativo. -The syntax is: `pattern:X(?!Y)`, it means "search `pattern:X`, but only if not followed by `pattern:Y`". +La sintassi è: `pattern:X(?!Y)`, significa "cerca `pattern:X`, ma solo se non seguito da `pattern:Y`". ```js run let str = "2 turkeys cost 60€"; -alert( str.match(/\d+\b(?!€)/g) ); // 2 (the price is not matched) +alert( str.match(/\d+\b(?!€)/g) ); // 2 (il prezzo non costituisce corrispondenza) ``` ## Lookbehind -Lookahead allows to add a condition for "what follows". +Lookahead permette di porre una condizione per "quello che segue". -Lookbehind is similar, but it looks behind. That is, it allows to match a pattern only if there's something before it. +Lookbehind è simile, ma cerca quello che precede. Consente quindi di trovare una corrispondenza per un pattern solo se c'è qualcosa prima di esso. -The syntax is: -- Positive lookbehind: `pattern:(?<=Y)X`, matches `pattern:X`, but only if there's `pattern:Y` before it. -- Negative lookbehind: `pattern:(? Date: Mon, 7 Jun 2021 10:40:48 +0200 Subject: [PATCH 4/7] Update 9-regular-expressions\14-regexp-lookahead-lookbehind --- .../14-regexp-lookahead-lookbehind/article.md | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/9-regular-expressions/14-regexp-lookahead-lookbehind/article.md b/9-regular-expressions/14-regexp-lookahead-lookbehind/article.md index 093ae6502..aee0b8ffa 100644 --- a/9-regular-expressions/14-regexp-lookahead-lookbehind/article.md +++ b/9-regular-expressions/14-regexp-lookahead-lookbehind/article.md @@ -86,22 +86,22 @@ alert( str.match(/(? Date: Tue, 8 Jun 2021 09:40:41 +0200 Subject: [PATCH 5/7] Update 9-regular-expressions\14-regexp-lookahead-lookbehind --- .../1-find-non-negative-integers/solution.md | 12 ++++++------ .../1-find-non-negative-integers/task.md | 8 +++----- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/9-regular-expressions/14-regexp-lookahead-lookbehind/1-find-non-negative-integers/solution.md b/9-regular-expressions/14-regexp-lookahead-lookbehind/1-find-non-negative-integers/solution.md index ebc12689d..37620e3ad 100644 --- a/9-regular-expressions/14-regexp-lookahead-lookbehind/1-find-non-negative-integers/solution.md +++ b/9-regular-expressions/14-regexp-lookahead-lookbehind/1-find-non-negative-integers/solution.md @@ -1,9 +1,9 @@ -The regexp for an integer number is `pattern:\d+`. +La regexp per un numero intero è `pattern:\d+`. -We can exclude negatives by prepending it with the negative lookbehind: `pattern:(? Date: Thu, 10 Jun 2021 09:50:56 +0200 Subject: [PATCH 6/7] Update 9-regular-expressions\14-regexp-lookahead-lookbehind --- .../2-insert-after-head/task.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/9-regular-expressions/14-regexp-lookahead-lookbehind/2-insert-after-head/task.md b/9-regular-expressions/14-regexp-lookahead-lookbehind/2-insert-after-head/task.md index be1a259f6..bcae85021 100644 --- a/9-regular-expressions/14-regexp-lookahead-lookbehind/2-insert-after-head/task.md +++ b/9-regular-expressions/14-regexp-lookahead-lookbehind/2-insert-after-head/task.md @@ -1,10 +1,10 @@ -# Insert After Head +# Inserimento dopo la sezione head -We have a string with an HTML Document. +Abbiamo una stringa e un documento HTML. -Write a regular expression that inserts `

Hello

` immediately after `` tag. The tag may have attributes. +Scrivete un'espressione regolare che inserisca `

Hello

` subito dopo il tag ``. Il tag può avere degli attributi. -For instance: +Per esempio: ```js let regexp = /your regular expression/; @@ -20,7 +20,7 @@ let str = ` str = str.replace(regexp, `

Hello

`); ``` -After that the value of `str` should be: +Dopo l'inserimento il valore di `str` dovrebbe essere: ```html

Hello

From 528c5df292c655e25d18f5dd0592d801b6fb9a67 Mon Sep 17 00:00:00 2001 From: idrusma Date: Thu, 10 Jun 2021 10:14:10 +0200 Subject: [PATCH 7/7] Update 9-regular-expressions\14-regexp-lookahead-lookbehind --- .../2-insert-after-head/solution.md | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/9-regular-expressions/14-regexp-lookahead-lookbehind/2-insert-after-head/solution.md b/9-regular-expressions/14-regexp-lookahead-lookbehind/2-insert-after-head/solution.md index b1d377d33..24b2a25b6 100644 --- a/9-regular-expressions/14-regexp-lookahead-lookbehind/2-insert-after-head/solution.md +++ b/9-regular-expressions/14-regexp-lookahead-lookbehind/2-insert-after-head/solution.md @@ -1,8 +1,8 @@ -In order to insert after the `` tag, we must first find it. We can use the regular expression pattern `pattern:` for that. +Per inserire qualcosa dopo il tag `` dobbiamo prima trovarlo. A questo scopo possiamo usare l'espressione regolare `pattern:`. -In this task we don't need to modify the `` tag. We only need to add the text after it. +In questa esercitazione non abbiamo bisogno di modificare il tag ``. Dobbiamo solo aggiungere del testo dopo di esso. -Here's how we can do it: +Ecco come possiamo farlo: ```js run let str = '......'; @@ -11,9 +11,9 @@ str = str.replace(//, '$&

Hello

'); alert(str); // ...

Hello

... ``` -In the replacement string `$&` means the match itself, that is, the part of the source text that corresponds to `pattern:`. It gets replaced by itself plus `

Hello

`. +Nella stringa di sostituzione `$&` identifica la stessa corrispondenza, in altre parole, la parte della stringa sorgente che trova riscontro con `pattern:`. Essa viene sostituita da se stessa più l'aggiunta di `

Hello

`. -An alternative is to use lookbehind: +L'uso del lookbehind costituisce un'alternativa: ```js run let str = '......'; @@ -22,15 +22,15 @@ str = str.replace(/(?<=)/, `

Hello

`); alert(str); // ...

Hello

... ``` -As you can see, there's only lookbehind part in this regexp. +Come potete osservare, c'è solo la parte di lookbehind in questa regexp. -It works like this: -- At every position in the text. -- Check if it's preceeded by `pattern:`. -- If it's so then we have the match. +Funziona in questo modo: +- Per ogni posizione nella stringa. +- Verifica se è preceduta da `pattern:`. +- In caso affermativo abbiamo trovato la corrispondenza. -The tag `pattern:` won't be returned. The result of this regexp is literally an empty string, but it matches only at positions preceeded by `pattern:`. +Il tag `pattern:` non verrà restituito. Il risultato di questa regexp è letteralmente una stringa vuota, ma individua le posizioni precedute da `pattern:`. -So it replaces the "empty line", preceeded by `pattern:`, with `

Hello

`. That's the insertion after ``. +Quindi sostituisce uno "spazio vuoto" preceduto da `pattern:`, con `

Hello

`. In altre parole effettua un inserimento dopo ``. -P.S. Regexp flags, such as `pattern:s` and `pattern:i` can also be useful: `pattern://si`. The `pattern:s` flag makes the dot `pattern:.` match a newline character, and `pattern:i` flag makes `pattern:` also match `match:` case-insensitively. +P.S. I flag `pattern:s` e `pattern:i` potrebbero inoltre risultare utili: `pattern://si`. Il flag `pattern:s` fa in modo che il `pattern:.` identifichi anche un carattere di nuova riga, e con il flag `pattern:i` otteniamo che `pattern:` e `match:` costituiscano entrambi un riscontro. pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

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:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy