Skip to content

Commit 3f6c5c5

Browse files
committed
Update 9-regular-expressions\13-regexp-alternation
1 parent 1dd0965 commit 3f6c5c5

File tree

4 files changed

+27
-27
lines changed

4 files changed

+27
-27
lines changed

9-regular-expressions/13-regexp-alternation/01-find-programming-language/solution.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

2-
The first idea can be to list the languages with `|` in-between.
2+
La prima idea potrebbe essere elencare i linguaggi separati da `|`.
33

4-
But that doesn't work right:
4+
Ma non funziona bene:
55

66
```js run
77
let regexp = /Java|JavaScript|PHP|C|C\+\+/g;
@@ -11,18 +11,18 @@ let str = "Java, JavaScript, PHP, C, C++";
1111
alert( str.match(regexp) ); // Java,Java,PHP,C,C
1212
```
1313

14-
The regular expression engine looks for alternations one-by-one. That is: first it checks if we have `match:Java`, otherwise -- looks for `match:JavaScript` and so on.
14+
L'interprete dell'espressione regolare cerca le alternanze una per una. In altre parole: per prima cosa cerca `match:Java`, se non la trova cerca `match:JavaScript` e così via.
1515

16-
As a result, `match:JavaScript` can never be found, just because `match:Java` is checked first.
16+
Il risultato è che `match:JavaScript` non trova mai corrispondenza proprio perché `match:Java` viene controllato per prima.
1717

18-
The same with `match:C` and `match:C++`.
18+
Lo stesso accade con `match:C` e `match:C++`.
1919

20-
There are two solutions for that problem:
20+
Ci sono due soluzioni per questo problema:
2121

22-
1. Change the order to check the longer match first: `pattern:JavaScript|Java|C\+\+|C|PHP`.
23-
2. Merge variants with the same start: `pattern:Java(Script)?|C(\+\+)?|PHP`.
22+
1. Cambiare l'ordine di verifica mettendo per primo il termine più lungo: `pattern:JavaScript|Java|C\+\+|C|PHP`.
23+
2. Unire le varianti che cominciano allo stesso modo: `pattern:Java(Script)?|C(\+\+)?|PHP`.
2424

25-
In action:
25+
In azione:
2626

2727
```js run
2828
let regexp = /Java(Script)?|C(\+\+)?|PHP/g;

9-regular-expressions/13-regexp-alternation/01-find-programming-language/task.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# Find programming languages
1+
# Trovate il nome dei linguaggi di programmazione
22

3-
There are many programming languages, for instance Java, JavaScript, PHP, C, C++.
3+
Ci sono molti linguaggi di programmazione, Per esempio Java, JavaScript, PHP, C, C++.
44

5-
Create a regexp that finds them in the string `subject:Java JavaScript PHP C++ C`:
5+
Create una regexp che li trovi nella stringa `subject:Java JavaScript PHP C++ C`:
66

77
```js
88
let regexp = /your regexp/g;

9-regular-expressions/13-regexp-alternation/02-find-matching-bbtags/solution.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11

2-
Opening tag is `pattern:\[(b|url|quote)\]`.
2+
Il tag di apertura è `pattern:\[(b|url|quote)\]`.
33

4-
Then to find everything till the closing tag -- let's use the pattern `pattern:.*?` with flag `pattern:s` to match any character including the newline and then add a backreference to the closing tag.
4+
Successivamente per trovare tutto fino al tag di chiusura usiamo il pattern `pattern:.*?` con il flag `pattern:s` per cercare la corrispondenza con ogni carattere inclusa una nuova riga. Per concludere aggiungiamo un riferimento all'indietro per il tag di chiusura.
55

6-
The full pattern: `pattern:\[(b|url|quote)\].*?\[/\1\]`.
6+
L'intero pattern risultante è: `pattern:\[(b|url|quote)\].*?\[/\1\]`.
77

8-
In action:
8+
In azione:
99

1010
```js run
1111
let regexp = /\[(b|url|quote)\].*?\[\/\1\]/gs;
@@ -20,4 +20,4 @@ let str = `
2020
alert( str.match(regexp) ); // [b]hello![/b],[quote][url]http://google.com[/url][/quote]
2121
```
2222

23-
Please note that besides escaping `pattern:[` and `pattern:]`, we had to escape a slash for the closing tag `pattern:[\/\1]`, because normally the slash closes the pattern.
23+
Si noti che oltre l'escape di `pattern:[` e `pattern:]`, abbiamo dovuto fare l'escape dello slash del tag di chiusura `pattern:[\/\1]`, poiché normalmente lo slash termina il pattern.

9-regular-expressions/13-regexp-alternation/02-find-matching-bbtags/task.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
1-
# Find bbtag pairs
1+
# Trovate le coppie di bbtag
22

3-
A "bb-tag" looks like `[tag]...[/tag]`, where `tag` is one of: `b`, `url` or `quote`.
3+
Un "bb-tag" si presenta così `[tag]...[/tag]`, in cui `tag` è uno tra: `b`, `url` o `quote`.
44

5-
For instance:
5+
Ad esempio:
66
```
77
[b]text[/b]
88
[url]http://google.com[/url]
99
```
1010

11-
BB-tags can be nested. But a tag can't be nested into itself, for instance:
11+
I BB-tags possono essere annidati. Un tag, tuttavia, non può essere contenuto all'interno di uno dello stesso tipo, ad esempio:
1212

1313
```
14-
Normal:
14+
Normale:
1515
[url] [b]http://google.com[/b] [/url]
1616
[quote] [b]text[/b] [/quote]
1717
18-
Can't happen:
18+
Non può verificarsi:
1919
[b][b]text[/b][/b]
2020
```
2121

22-
Tags can contain line breaks, that's normal:
22+
I tag possono contenere interruzioni di linea, questo è del tutto normale:
2323

2424
```
2525
[quote]
2626
[b]text[/b]
2727
[/quote]
2828
```
2929

30-
Create a regexp to find all BB-tags with their contents.
30+
Create una regexp per trovare tutti i BB-tags con il loro contenuto.
3131

32-
For instance:
32+
Per esempio:
3333

3434
```js
3535
let regexp = /your regexp/flags;
@@ -38,7 +38,7 @@ let str = "..[url]http://google.com[/url]..";
3838
alert( str.match(regexp) ); // [url]http://google.com[/url]
3939
```
4040

41-
If tags are nested, then we need the outer tag (if we want we can continue the search in its content):
41+
In caso di tag annidati ci occorre il tag esterno (se lo desideriamo possiamo continuare la ricerca nel contenuto appena ricavato):
4242

4343
```js
4444
let regexp = /your regexp/flags;

0 commit comments

Comments
 (0)