Skip to content

Commit aeda744

Browse files
committed
Update 9-regular-expressions\13-regexp-alternation
1 parent af7a081 commit aeda744

File tree

1 file changed

+15
-15
lines changed
  • 9-regular-expressions/13-regexp-alternation

1 file changed

+15
-15
lines changed

9-regular-expressions/13-regexp-alternation/article.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
# Alternation (OR) |
1+
# Alternanza (OR) |
22

3-
Alternation is the term in regular expression that is actually a simple "OR".
3+
Alternanza è un termine usato nelle espressioni regolari che, in realtà, consiste in un semplice "OR".
44

5-
In a regular expression it is denoted with a vertical line character `pattern:|`.
5+
È indicata con un carattere di linea verticale `pattern:|`.
66

7-
For instance, we need to find programming languages: HTML, PHP, Java or JavaScript.
7+
Supponiamo di aver bisogno di trovare il nome di un linguaggio di programmazione: HTML, PHP, Java o JavaScript.
88

9-
The corresponding regexp: `pattern:html|php|java(script)?`.
9+
Ecco la regexp corrispondente: `pattern:html|php|java(script)?`.
1010

11-
A usage example:
11+
E ora un esempio d'uso:
1212

1313
```js run
1414
let regexp = /html|php|css|java(script)?/gi;
@@ -18,20 +18,20 @@ let str = "First HTML appeared, then CSS, then JavaScript";
1818
alert( str.match(regexp) ); // 'HTML', 'CSS', 'JavaScript'
1919
```
2020

21-
We already saw a similar thing -- square brackets. They allow to choose between multiple characters, for instance `pattern:gr[ae]y` matches `match:gray` or `match:grey`.
21+
Abbiamo già incontrato una funzionalità simile: le parentesi quadre. Essi permettono di scegliere tra più caratteri, ad esempio `pattern:gr[ae]y` trova corrispondenza con `match:gray` o `match:grey`.
2222

23-
Square brackets allow only characters or character classes. Alternation allows any expressions. A regexp `pattern:A|B|C` means one of expressions `A`, `B` or `C`.
23+
Le parentesi quadre consentono solo caratteri o classi di caratteri. L'alternanza consente qualsiasi espressione. Una regexp `pattern:A|B|C` significa una delle espressioni `A`, `B` o `C`.
2424

25-
For instance:
25+
Per esempio:
2626

27-
- `pattern:gr(a|e)y` means exactly the same as `pattern:gr[ae]y`.
28-
- `pattern:gra|ey` means `match:gra` or `match:ey`.
27+
- `pattern:gr(a|e)y` ha lo stesso identico significato di `pattern:gr[ae]y`.
28+
- `pattern:gra|ey` significa `match:gra` o `match:ey`.
2929

30-
To apply alternation to a chosen part of the pattern, we can enclose it in parentheses:
31-
- `pattern:I love HTML|CSS` matches `match:I love HTML` or `match:CSS`.
32-
- `pattern:I love (HTML|CSS)` matches `match:I love HTML` or `match:I love CSS`.
30+
Per applicare l'alternanza ad una determinata parte di un pattern, dobbiamo racchiuderla tra parentesi:
31+
- `pattern:I love HTML|CSS` trova `match:I love HTML` o `match:CSS`.
32+
- `pattern:I love (HTML|CSS)` corrisponde a `match:I love HTML` o `match:I love CSS`.
3333

34-
## Example: regexp for time
34+
## Esempio: una regexp per un orario
3535

3636
In previous articles there was a task to build a regexp for searching time in the form `hh:mm`, for instance `12:00`. But a simple `pattern:\d\d:\d\d` is too vague. It accepts `25:99` as the time (as 99 minutes match the pattern, but that time is invalid).
3737

0 commit comments

Comments
 (0)