|
1 |
| -# Word boundary: \b |
| 1 | +# Confine di parola: \b |
2 | 2 |
|
3 |
| -A word boundary `pattern:\b` is a test, just like `pattern:^` and `pattern:$`. |
| 3 | +Il confine di parola `pattern:\b` è un test, proprio come `pattern:^` e `pattern:$`. |
4 | 4 |
|
5 |
| -When the regexp engine (program module that implements searching for regexps) comes across `pattern:\b`, it checks that the position in the string is a word boundary. |
| 5 | +Quando l'interprete delle regexp (il modulo software che cerca all'interno delle espressioni regolari) incontra `pattern:\b`, verifica se la posizione nella stringa sia un confine di parola. |
6 | 6 |
|
7 |
| -There are three different positions that qualify as word boundaries: |
| 7 | +Ci sono tre differenti posizioni che qualificano il confine di parola: |
8 | 8 |
|
9 |
| -- At string start, if the first string character is a word character `pattern:\w`. |
10 |
| -- Between two characters in the string, where one is a word character `pattern:\w` and the other is not. |
11 |
| -- At string end, if the last string character is a word character `pattern:\w`. |
| 9 | +- Ad inizio stringa, se il primo carattere di essa è un carattere di parola `pattern:\w`. |
| 10 | +- Tra due caratteri di una stringa, laddove il primo sia un carattere di parola `pattern:\w` e l'altro no. |
| 11 | +- A fine stringa, se l'ultimo carattere è un carattere di parola `pattern:\w`. |
12 | 12 |
|
13 |
| -For instance, regexp `pattern:\bJava\b` will be found in `subject:Hello, Java!`, where `subject:Java` is a standalone word, but not in `subject:Hello, JavaScript!`. |
| 13 | +Ad esempio, la regexp `pattern:\bJava\b` troverà corrispondenza in `subject:Hello, Java!`, dove `subject:Java` è una parola a sé, ma non troverà alcuna corrispondenza in `subject:Hello, JavaScript!`. |
14 | 14 |
|
15 | 15 | ```js run
|
16 | 16 | alert( "Hello, Java!".match(/\bJava\b/) ); // Java
|
17 | 17 | alert( "Hello, JavaScript!".match(/\bJava\b/) ); // null
|
18 | 18 | ```
|
19 | 19 |
|
20 |
| -In the string `subject:Hello, Java!` following positions correspond to `pattern:\b`: |
| 20 | +Nella stringa `subject:Hello, Java!` trovano riscontro in `pattern:\b` le seguenti posizioni: |
21 | 21 |
|
22 | 22 | 
|
23 | 23 |
|
24 |
| -So, it matches the pattern `pattern:\bHello\b`, because: |
| 24 | +Pertanto la corrispondenza con il pattern `pattern:\bHello\b` viene trovata perché: |
25 | 25 |
|
26 |
| -1. At the beginning of the string matches the first test `pattern:\b`. |
27 |
| -2. Then matches the word `pattern:Hello`. |
28 |
| -3. Then the test `pattern:\b` matches again, as we're between `subject:o` and a comma. |
| 26 | +1. All'inizio della stringa trova riscontro con il primo test `pattern:\b`. |
| 27 | +2. Successivamente identifica la parola `pattern:Hello`. |
| 28 | +3. Infine trova ancora corrispondenza con il test `pattern:\b`, dal momento che la posizione corrente è tra una `subject:o` e una virgola. |
29 | 29 |
|
30 |
| -So the pattern `pattern:\bHello\b` would match, but not `pattern:\bHell\b` (because there's no word boundary after `l`) and not `Java!\b` (because the exclamation sign is not a wordly character `pattern:\w`, so there's no word boundary after it). |
| 30 | +Viene quindi individuato il pattern `pattern:\bHello\b`, ma non `pattern:\bHell\b` (perché non c'è un confine di parola dopo la `l`) e non `Java!\b` (perché il punto esclamativo non è un carattere di parola `pattern:\w`, quindi non c'è confine di parola dopo di esso). |
31 | 31 |
|
32 | 32 | ```js run
|
33 | 33 | alert( "Hello, Java!".match(/\bHello\b/) ); // Hello
|
34 | 34 | alert( "Hello, Java!".match(/\bJava\b/) ); // Java
|
35 |
| -alert( "Hello, Java!".match(/\bHell\b/) ); // null (no match) |
36 |
| -alert( "Hello, Java!".match(/\bJava!\b/) ); // null (no match) |
| 35 | +alert( "Hello, Java!".match(/\bHell\b/) ); // null (nessuna corrispondenza) |
| 36 | +alert( "Hello, Java!".match(/\bJava!\b/) ); // null (nessuna corrispondenza) |
37 | 37 | ```
|
38 | 38 |
|
39 |
| -We can use `pattern:\b` not only with words, but with digits as well. |
| 39 | +Possiamo usare `pattern:\b` anche con i numeri non solo con le parole. |
40 | 40 |
|
41 |
| -For example, the pattern `pattern:\b\d\d\b` looks for standalone 2-digit numbers. In other words, it looks for 2-digit numbers that are surrounded by characters different from `pattern:\w`, such as spaces or punctuation (or text start/end). |
| 41 | +Il pattern `pattern:\b\d\d\b`, ad esempio, cerca due caratteri numerici a sé stanti. In altre parole, cerca un numero di due cifre delimitato da caratteri differenti da `pattern:\w`, come spazi o punteggiatura (o l'inizio/la fine della stringa). |
42 | 42 |
|
43 | 43 | ```js run
|
44 | 44 | alert( "1 23 456 78".match(/\b\d\d\b/g) ); // 23,78
|
45 | 45 | alert( "12,34,56".match(/\b\d\d\b/g) ); // 12,34,56
|
46 | 46 | ```
|
47 | 47 |
|
48 |
| -```warn header="Word boundary `pattern:\b` doesn't work for non-latin alphabets" |
49 |
| -The word boundary test `pattern:\b` checks that there should be `pattern:\w` on the one side from the position and "not `pattern:\w`" - on the other side. |
| 48 | +```warn header="Il confine di parola `pattern:\b` funziona solo con l'alfabeto latino" |
| 49 | +Il test di confine parola `pattern:\b` controlla che ci sia `pattern:\w` da un lato della posizione e che non ci sia `pattern:\w` dall'altro lato. |
50 | 50 |
|
51 |
| -But `pattern:\w` means a latin letter `a-z` (or a digit or an underscore), so the test doesn't work for other characters, e.g. cyrillic letters or hieroglyphs. |
| 51 | +Ma `pattern:\w` significa una lettera dell'alfabeto latino `a-z` (o un numero o un underscore), pertanto il test non è efficace per altri caratteri, es. caratteri cirillici o simboli grafici. |
52 | 52 | ```
|
0 commit comments