|
1 | 1 |
|
2 | | -# Unicode character properties \p |
| 2 | +# Proprietà dei caratteri Unicode \p |
3 | 3 |
|
4 | | -[Unicode](https://en.wikipedia.org/wiki/Unicode), the encoding format used by JavaScript strings, has a lot of properties for different characters (or, technically, code points). They describe which "categories" character belongs to, and a variety of technical details. |
| 4 | +[Unicode](https://en.wikipedia.org/wiki/Unicode), il formato di codifica usato dalle stringhe di JavaScript, ha molte proprietà per diversi caratteri. Esse descrivono a quali "categorie" appartiene il carattere, e una varietà di dettagli tecnici. |
5 | 5 |
|
6 | | -In regular expressions these can be set by `\p{…}`. And there must be flag `'u'`. |
| 6 | +Nelle espressioni regolari queste possono essere impostate con `\p{…}`. E deve esserci la flag `'u'`. |
7 | 7 |
|
8 | | -For instance, `\p{Letter}` denotes a letter in any of language. We can also use `\p{L}`, as `L` is an alias of `Letter`, there are shorter aliases for almost every property. |
| 8 | +Per esempio, `\p{Letter}` indica una lettera in qualsiasi lingua. Possiamo anche usare `\p{L}`, o `L` al posto di `Letter`, ci sono alias più corti quasi per tutte le proprietà. |
9 | 9 |
|
10 | | -Here's the main tree of properties: |
| 10 | +Qui c'è l'albero principale delle proprietà: |
11 | 11 |
|
12 | | -- Letter `L`: |
13 | | - - lowercase `Ll`, modifier `Lm`, titlecase `Lt`, uppercase `Lu`, other `Lo` |
14 | | -- Number `N`: |
15 | | - - decimal digit `Nd`, letter number `Nl`, other `No` |
16 | | -- Punctuation `P`: |
17 | | - - connector `Pc`, dash `Pd`, initial quote `Pi`, final quote `Pf`, open `Ps`, close `Pe`, other `Po` |
18 | | -- Mark `M` (accents etc): |
19 | | - - spacing combining `Mc`, enclosing `Me`, non-spacing `Mn` |
20 | | -- Symbol `S`: |
21 | | - - currency `Sc`, modifier `Sk`, math `Sm`, other `So` |
22 | | -- Separator `Z`: |
23 | | - - line `Zl`, paragraph `Zp`, space `Zs` |
24 | | -- Other `C`: |
25 | | - - control `Cc`, format `Cf`, not assigned `Cn`, private use `Co`, surrogate `Cs` |
| 12 | +- Lettera `L`: |
| 13 | + - minuscolo `Ll`, modificatore `Lm`, titolo `Lt`, maiuscolo `Lu`, altro `Lo` |
| 14 | +- Numero `N`: |
| 15 | + - cifra decimale `Nd`, numero letterale `Nl`, altro `No` |
| 16 | +- Punteggiatura `P`: |
| 17 | + - connettore `Pc`, trattino `Pd`, apri virgolette `Pi`, chiudi virgolette `Pf`, apri `Ps`, chiudi `Pe`, altro `Po` |
| 18 | +- Mark `M` (accenti ecc.): |
| 19 | + - combinazione di spazi `Mc`, simboli di enclosing `Me`, caratteri non-spacing `Mn` |
| 20 | +- Simbolo `S`: |
| 21 | + - valuta `Sc`, modificatore `Sk`, matematico `Sm`, altro `So` |
| 22 | +- Separatore `Z`: |
| 23 | + - linea `Zl`, paragrafo `Zp`, spazio `Zs` |
| 24 | +- Altro `C`: |
| 25 | + - controllo `Cc`, formato `Cf`, non assegnato `Cn`, uso privato `Co`, surrogato `Cs` |
26 | 26 |
|
27 | | -```smart header="More information" |
28 | | -Interested to see which characters belong to a property? There's a tool at <http://cldr.unicode.org/unicode-utilities/list-unicodeset> for that. |
| 27 | +```smart header="Maggiori informazioni" |
| 28 | +Ti interessa scoprire quali caratteri appartengono a una proprietà? C'è uno strumento in <http://cldr.unicode.org/unicode-utilities/list-unicodeset> che serve a questo. |
29 | 29 |
|
30 | | -You could also explore properties at [Character Property Index](http://unicode.org/cldr/utility/properties.jsp). |
| 30 | +Potresti anche esplorare le proprietà in [Character Property Index](http://unicode.org/cldr/utility/properties.jsp). |
31 | 31 |
|
32 | | -For the full Unicode Character Database in text format (along with all properties), see <https://www.unicode.org/Public/UCD/latest/ucd/>. |
| 32 | +Per il Database completo dei Caratteri Unicode in formato testuale (insieme a tutte le proprietà), vedi <https://www.unicode.org/Public/UCD/latest/ucd/>. |
33 | 33 | ``` |
34 | 34 |
|
35 | | -There are also other derived categories, like: |
36 | | -- `Alphabetic` (`Alpha`), includes Letters `L`, plus letter numbers `Nl` (e.g. roman numbers Ⅻ), plus some other symbols `Other_Alphabetic` (`OAltpa`). |
37 | | -- `Hex_Digit` includes hexadecimal digits: `0-9`, `a-f`. |
38 | | -- ...Unicode is a big beast, it includes a lot of properties. |
| 35 | +Ci sono anche altre categorie derivate, come: |
| 36 | +- `Alphabetic` (`Alpha`), include Lettere `L`, più numeri letterali `Nl` (es. i numeri romani Ⅻ), più qualche altro simbolo `Other_Alphabetic` (`OAltpa`). |
| 37 | +- `Hex_Digit` include i numeri esadecimali: `0-9`, `a-f`. |
| 38 | +- ...Unicode è un sistema complesso, include moltissime proprietà. |
39 | 39 |
|
40 | | -For instance, let's look for a 6-digit hex number: |
| 40 | +Per esempio, cerchiamo un numero esadecimale a 6 cifre: |
41 | 41 |
|
42 | 42 | ```js run |
43 | | -let reg = /\p{Hex_Digit}{6}/u; // flag 'u' is required |
| 43 | +let reg = /\p{Hex_Digit}{6}/u; // è richiesta la flag 'u' |
44 | 44 |
|
45 | 45 | alert("color: #123ABC".match(reg)); // 123ABC |
46 | 46 | ``` |
47 | 47 |
|
48 | | -There are also properties with a value. For instance, Unicode "Script" (a writing system) can be Cyrillic, Greek, Arabic, Han (Chinese) etc, the [list is long]("https://en.wikipedia.org/wiki/Script_(Unicode)"). |
| 48 | +Ci sono anche proprietà con un valore. Ad esempio, Unicode "Script" (un sistema di scrittura) può essere Cirillico, Greco, Arabo, Han (Cinese) ecc, la [lista è lunga]("https://en.wikipedia.org/wiki/Script_(Unicode)"). |
49 | 49 |
|
50 | | -To search for characters in certain scripts ("alphabets"), we should supply `Script=<value>`, e.g. to search for cyrillic letters: `\p{sc=Cyrillic}`, for Chinese glyphs: `\p{sc=Han}`, etc: |
| 50 | +Per cercare caratteri in certi script ("alfabeti"), dovremmo fornire `Script=<value>`, ad esempio per cercare lettere in Cirillico: `\p{sc=Cyrillic}`, per glifi Cinesi: `\p{sc=Han}`, ecc: |
51 | 51 |
|
52 | 52 | ```js run |
53 | | -let regexp = /\p{sc=Han}+/gu; // get chinese words |
| 53 | +let regexp = /\p{sc=Han}+/gu; // ottieni parole cinesi |
54 | 54 |
|
55 | 55 | let str = `Hello Привет 你好 123_456`; |
56 | 56 |
|
57 | 57 | alert( str.match(regexp) ); // 你好 |
58 | 58 | ``` |
59 | 59 |
|
60 | | -## Building multi-language \w |
| 60 | +## Costruire un multi linguaggio \w |
61 | 61 |
|
62 | | -The pattern `pattern:\w` means "wordly characters", but doesn't work for languages that use non-Latin alphabets, such as Cyrillic and others. It's just a shorthand for `[a-zA-Z0-9_]`, so `pattern:\w+` won't find any Chinese words etc. |
| 62 | +Il pattern `pattern:\w` vuol dire "caratteri per formare parole", ma non funziona per lingue che usano alfabeti non Latini, come il Cirillico e altri. È solo un'abbreviazione per `[a-zA-Z0-9_]`, quindi `pattern:\w+` non troverà nessuna parola Cinese ecc. |
63 | 63 |
|
64 | | -Let's make a "universal" regexp, that looks for wordly characters in any language. That's easy to do using Unicode properties: |
| 64 | +Creiamo una regexp "universale", che cerca "caratteri letterari" in qualsiasi lingua. È semplice da fare utilizzando le proprietà di Unicode: |
65 | 65 |
|
66 | 66 | ```js |
67 | 67 | /[\p{Alphabetic}\p{Mark}\p{Decimal_Number}\p{Connector_Punctuation}\p{Join_Control}]/u |
68 | 68 | ``` |
69 | 69 |
|
70 | | -Let's decipher. Just as `pattern:\w` is the same as `pattern:[a-zA-Z0-9_]`, we're making a set of our own, that includes: |
| 70 | +Decifriamolo. Proprio come `pattern:\w` è lo stesso di `pattern:[a-zA-Z0-9_]`, stiamo creando un nostro set personalizzato, che include: |
71 | 71 |
|
72 | | -- `Alphabetic` for letters, |
73 | | -- `Mark` for accents, as in Unicode accents may be represented by separate code points, |
74 | | -- `Decimal_Number` for numbers, |
75 | | -- `Connector_Punctuation` for the `'_'` character and alike, |
76 | | -- `Join_Control` -– two special code points with hex codes `200c` and `200d`, used in ligatures e.g. in arabic. |
| 72 | +- `Alphabetic` per le lettere, |
| 73 | +- `Mark` per accenti, dato che in Unicode gli accenti potrebbero essere rappresentati con codici separati, |
| 74 | +- `Decimal_Number` per i numeri, |
| 75 | +- `Connector_Punctuation` per il carattere `'_'` e simili, |
| 76 | +- `Join_Control` -– due codici speciali con codice esadecimale `200c` e `200d`, usati ad esempio in Arabo. |
77 | 77 |
|
78 | | -Or, if we replace long names with aliases (a list of aliases [here](https://www.unicode.org/Public/UCD/latest/ucd/PropertyValueAliases.txt)): |
| 78 | +O, se sostituiamo nomi lunghi con degli alias (una lista di alias [qui](https://www.unicode.org/Public/UCD/latest/ucd/PropertyValueAliases.txt)): |
79 | 79 |
|
80 | 80 | ```js run |
81 | 81 | let regexp = /([\p{Alpha}\p{M}\p{Nd}\p{Pc}\p{Join_C}]+)/gu; |
|
0 commit comments