You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
JavaScript uses [Unicode encoding](https://en.wikipedia.org/wiki/Unicode) for strings. Most characters are encoded with 2 bytes, but that allows to represent at most 65536 characters.
3
+
자바스크립트는 문자열에 [유니코드 인코딩](https://en.wikipedia.org/wiki/Unicode)을 사용합니다. 대부분의 문자는 2바이트로 인코딩되어있는데 2바이트로는 최대 65,536개의 글자밖에 표현할 수 없습니다.
4
4
5
-
That range is not big enough to encode all possible characters, that's why some rare characters are encoded with 4 bytes, for instance like `𝒳` (mathematical X) or `😄` (a smile), some hieroglyphs and so on.
5
+
65,536자는 모든 글자를 인코딩하기에는 부족한 숫자입니다. 그래서 일부 문자는 4바이트로 인코딩되어있습니다. 예를 들면 `𝒳`(수학에서 사용하는 X)나 `😄`(웃는 표정), 일부 상형 문자 등이 있죠.
6
6
7
-
Here are the unicode values of some characters:
7
+
다음은 일부 문자의 유니코드 값입니다.
8
8
9
-
|Character|Unicode|Bytes count in unicode|
9
+
|문자|유니코드|유니코드의 바이트 수|
10
10
|------------|---------|--------|
11
11
| a |`0x0061`| 2 |
12
12
| ≈ |`0x2248`| 2 |
13
13
|𝒳|`0x1d4b3`| 4 |
14
14
|𝒴|`0x1d4b4`| 4 |
15
15
|😄|`0x1f604`| 4 |
16
16
17
-
So characters like `a` and `≈` occupy 2 bytes, while codes for `𝒳`, `𝒴` and `😄` are longer, they have 4 bytes.
17
+
보다시피 `a`나 `≈`같은 문자는 2바이트를 차지하고 `𝒳`, `𝒴`, `😄`같은 문자는 코드값이 더 길고 4바이트를 차지합니다.
18
18
19
-
Long time ago, when JavaScript language was created, Unicode encoding was simpler: there were no 4-byte characters. So, some language features still handle them incorrectly.
19
+
오래전에 자바스크립트 언어가 탄생했을 때는 유니코드 인코딩은 지금보다 단순했습니다. 4바이트 문자가 없었죠. 그래서 일부 언어 기능은 아직도 이런 문자들을 정확하게 다루지 못합니다.
20
20
21
-
For instance,`length` thinks that here are two characters:
21
+
그중 하나로`length`는 다음 경우에서 문자가 두 개 있다고 봅니다.
22
22
23
23
```js run
24
24
alert('😄'.length); // 2
25
25
alert('𝒳'.length); // 2
26
26
```
27
27
28
-
...But we can see that there's only one, right? The point is that `length` treats 4 bytes as two 2-byte characters. That's incorrect, because they must be considered only together (so-called "surrogate pair", you can read about them in the article <info:string>).
28
+
하지만 분명 문자는 하나잖아요? 여기서 중요한 것은 `length`는 4바이트 문자를 2바이트 문자 2개로 취급한다는 것입니다. 4바이트를 하나로 묶어서 취급해야 하므로 올바르지 않은 결과입니다.(이런 문자를 '서로게이트 쌍'이라고 합니다. <info:string>에서 서로게이트 쌍에 대해 읽어볼 수 있습니다.)
29
29
30
-
By default, regular expressions also treat 4-byte "long characters" as a pair of 2-byte ones. And, as it happens with strings, that may lead to odd results. We'll see that a bit later, in the article <info:regexp-character-sets-and-ranges>.
30
+
기본적으로는 정규 표현식도 4바이트의 '긴 문자'를 2바이트 문자 2개로 취급합니다. 문자열의 경우처럼 이런 방식은 잘못된 결과로 이어질 수 있습니다. 나중에 <info:regexp-character-sets-and-ranges>에서 다시 알아볼 것입니다.
31
31
32
-
Unlike strings, regular expressions have flag `pattern:u`that fixes such problems. With such flag, a regexp handles 4-byte characters correctly. And also Unicode property search becomes available, we'll get to it next.
32
+
문자열과 다르게 정규 표현식에는 이런 문제를 해결할 수 있는 `pattern:u`플래그가 있습니다. `pattern:u` 플래그를 사용하면 정규식은 4바이트 문자를 올바르게 처리합니다. 그리고 유니코드 프로퍼티(Unicode property)를 사용한 검색이 가능해집니다. 바로 알아보죠.
33
33
34
-
## Unicode properties \p{...}
34
+
## 유니코드 프로퍼티 \p{...}
35
35
36
-
```warn header="Not supported in Firefox and Edge"
37
-
Despite being a part of the standard since 2018, unicode properties are not supported in Firefox ([bug](https://bugzilla.mozilla.org/show_bug.cgi?id=1361876)) and Edge ([bug](https://github.com/Microsoft/ChakraCore/issues/2969)).
36
+
```warn header="Firefox와 Edge에서 미지원"
37
+
2018년부터 표준에 포함되었지만 Firefox([버그](https://bugzilla.mozilla.org/show_bug.cgi?id=1361876))와 Edge([버그](https://github.com/Microsoft/ChakraCore/issues/2969))는 유니코드 프로퍼티를 아직 지원하지 않습니다.
38
38
39
-
There's [XRegExp](http://xregexp.com) library that provides "extended" regular expressions with cross-browser support for unicode properties.
39
+
유니코드 프로퍼티의 크로스 브라우저 지원을 포함한 정규 표현식의 '확장' 기능을 제공하는 [XRegExp](http://xregexp.com) 라이브러리가 있습니다.
40
40
```
41
41
42
-
Every character in Unicode has a lot of properties. They describe what "category" the character belongs to, contain miscellaneous information about it.
42
+
유니코드의 모든 문자는 다양한 프로퍼티를 가집니다. 프로퍼티는 문자가 어떤 '범주'에 속하는지 설명하기도 하고 그 외에도 문자의 여러 가지 정보를 담고 있습니다.
43
43
44
-
For instance, if a character has `Letter`property, it means that the character belongs to an alphabet (of any language). And `Number`property means that it's a digit: maybe Arabic or Chinese, and so on.
44
+
예를 들어 문자에 `Letter`프로퍼티가 있다면 그 문자는 어떠한 언어의 글자라는 뜻입니다. `Number`프로퍼티가 있다면 아라비아 숫자든 한자 숫자든 숫자라는 뜻이죠.
45
45
46
-
We can search for characters with a property, written as `pattern:\p{…}`. To use `pattern:\p{…}`, a regular expression must have flag `pattern:u`.
46
+
`pattern:\p{…}`를 사용하면 프로퍼티를 통해 문자를 찾을 수 있습니다. `pattern:\p{…}`를 사용하기 위해서는 정규 표현식에 `pattern:u` 플래그가 반드시 있어야 합니다.
47
47
48
-
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.
48
+
예시로 `p{Letter}`는 언어의 글자를 표기하는 방법입니다. `p{L}`을 대신 사용할 수도 있습니다. 여기서 `L`은`Letter`의 약자입니다. 거의 모든 프로퍼티에 이렇게 짧게 쓸 수 있는 약자가 있습니다.
49
49
50
-
In the example below three kinds of letters will be found: English, Georgean and Korean.
50
+
아래 예시에서는 영문자, 조지아 문자, 한글 3종류의 글자를 검색합니다.
51
51
52
52
```js run
53
53
let str ="A ბ ㄱ";
54
54
55
55
alert( str.match(/\p{L}/gu) ); // A,ბ,ㄱ
56
-
alert( str.match(/\p{L}/g) ); // null (no matches, as there's no flag "u")
56
+
alert( str.match(/\p{L}/g) ); // null ('u' 플래그가 없어서 일치 결과 없음)
57
57
```
58
58
59
-
Here's the main character categories and their subcategories:
60
-
61
-
- Letter `L`:
62
-
- lowercase `Ll`
63
-
- modifier `Lm`,
64
-
- titlecase `Lt`,
65
-
- uppercase `Lu`,
66
-
- other `Lo`.
67
-
- Number `N`:
68
-
- decimal digit `Nd`,
69
-
- letter number `Nl`,
70
-
- other `No`.
71
-
- Punctuation `P`:
72
-
- connector `Pc`,
73
-
- dash `Pd`,
74
-
- initial quote `Pi`,
75
-
- final quote `Pf`,
76
-
- open `Ps`,
77
-
- close `Pe`,
78
-
- other `Po`.
79
-
- Mark `M` (accents etc):
80
-
- spacing combining `Mc`,
81
-
- enclosing `Me`,
82
-
- non-spacing `Mn`.
83
-
- Symbol `S`:
84
-
- currency `Sc`,
85
-
- modifier `Sk`,
86
-
- math `Sm`,
87
-
- other `So`.
88
-
- Separator `Z`:
89
-
- line `Zl`,
90
-
- paragraph `Zp`,
91
-
- space `Zs`.
92
-
- Other `C`:
93
-
- control `Cc`,
94
-
- format `Cf`,
95
-
- not assigned `Cn`,
96
-
-- private use `Co`,
97
-
- surrogate `Cs`.
98
-
99
-
100
-
So, e.g. if we need letters in lower case, we can write `pattern:\p{Ll}`, punctuation signs: `pattern:\p{P}` and so on.
101
-
102
-
There are also other derived categories, like:
103
-
-`Alphabetic`(`Alpha`), includes Letters `L`, plus letter numbers `Nl` (e.g. Ⅻ - a character for the roman number 12), plus some other symbols `Other_Alphabetic`(`OAlpha`).
104
-
-`Hex_Digit` includes hexadecimal digits: `0-9`, `a-f`.
105
-
-...And so on.
106
-
107
-
Unicode supports many different properties, their full list would require a lot of space, so here are the references:
108
-
109
-
-List all properties by a character: <https://unicode.org/cldr/utility/character.jsp>.
110
-
-List all characters by a property: <https://unicode.org/cldr/utility/list-unicodeset.jsp>.
111
-
-Short aliases for properties: <https://www.unicode.org/Public/UCD/latest/ucd/PropertyValueAliases.txt>.
112
-
-A full base of Unicode characters in text format, with all properties, is here: <https://www.unicode.org/Public/UCD/latest/ucd/>.
113
-
114
-
### Example: hexadecimal numbers
115
-
116
-
For instance, let's look for hexadecimal numbers, written as `xFF`, where `F`is a hex digit (0..1 or A..F).
117
-
118
-
A hex digit can be denoted as `pattern:\p{Hex_Digit}`:
59
+
다음은 주요 문자 범주와 각각의 하위 범주 목록입니다.
60
+
61
+
-문자(Letter)`L`:
62
+
-소문자(lowercase)`Ll`
63
+
-조정(modifier)`Lm`
64
+
-단어의 첫 글자를 대문자로(titlecase)`Lt`
65
+
-대문자(uppercase)`Lu`
66
+
-기타(other)`Lo`
67
+
-숫자(Number)`N`:
68
+
-10진수(decimal digit)`Nd`
69
+
-문자(letter number)`Nl`
70
+
-기타(other)`No`
71
+
-문장 부호(Punctuation)`P`:
72
+
-연결선(connector)`Pc`
73
+
-대시(dash)`Pd`
74
+
-처음 따옴표(initial quote)`Pi`
75
+
-마지막 따옴표(final quote)`Pf`
76
+
-열기(open)`Ps`
77
+
-닫기(close)`Pe`
78
+
-기타(other)`Po`
79
+
-표시(Mark)`M` (강세 등):
80
+
-간격 결합(spacing combining)`Mc`
81
+
-묶음(enclosing)`Me`
82
+
-비공백(non-spacing)`Mn`
83
+
-기호(Symbol)`S`:
84
+
-통화(currency)`Sc`
85
+
-수정(modifier)`Sk`
86
+
-수학(math)`Sm`
87
+
-기타(other)`So`
88
+
-구분 기호(Separator)`Z`:
89
+
-줄(line)`Zl`
90
+
-단락(paragraph)`Zp`
91
+
-공백(space)`Zs`
92
+
-기타(Other)`C`:
93
+
-제어(control)`Cc`
94
+
-형식(format)`Cf`
95
+
-할당되지 않음(not assigned)`Cn`
96
+
- 사용자 지정(private use)`Co`
97
+
-서로게이트(surrogate)`Cs`
98
+
99
+
100
+
예를 들어 소문자를 찾아야 한다면 `pattern:\p{Ll}`을, 문장 부호를 찾아야 한다면 `pattern:\p{P}`를 사용하는 식으로 검색할 수 있습니다.
101
+
102
+
또한 다음과 같이 파생된 범주도 있습니다.
103
+
-`Alphabetic`(`Alpha`)는 Letters `L`와 로마 숫자 Ⅻ같이 문자로 된 숫자 `Nl`에 더해서 `Other_Alphabetic`(`OAlpha`)에 속한 문자들을 모두 포함합니다.
104
+
-`Hex_digit`은 16진수 숫자인 `0-9`, `a-f`를 포함합니다.
105
+
-이것 말고도 더 있죠.
106
+
107
+
유니코드는 정말 다양한 프로퍼티를 지원합니다. 모든 걸 나열하려면 공간이 너무 많이 필요하니 참고할 수 있는 문서를 알려드립니다.
-텍스트 형식으로 정리된 유니코드 문자와 각 문자의 모든 프로퍼티: <https://www.unicode.org/Public/UCD/latest/ucd/>
113
+
114
+
### 예시: 16진수
115
+
116
+
실제 사례로 16진수를 찾아봅시다. `xFF` 형식으로 쓰고 `F`자리에는 16진수의 숫자(0..1이나 A..F)가 들어갑니다.
117
+
118
+
16진수 숫자는 `pattern:\p{Hex_Digit}`로 표기합니다.
119
119
120
120
```js run
121
121
let regexp =/x\p{Hex_Digit}\p{Hex_Digit}/u;
122
122
123
123
alert("number: xAF".match(regexp)); // xAF
124
124
```
125
125
126
-
### Example: Chinese hieroglyphs
126
+
### 예시: 한자
127
127
128
-
Let's look for Chinese hieroglyphs.
128
+
한자를 검색해봅시다.
129
129
130
-
There's a unicode property `Script` (a writing system), that may have a value: `Cyrillic`, `Greek`, `Arabic`, `Han` (Chinese) and so on, [here's the full list]("https://en.wikipedia.org/wiki/Script_(Unicode)").
130
+
`Script`(표기 체계)라는 유니코드 프로퍼티가 있습니다. `Script`는 `Cyrillic`(키릴 문자), `Greek`(그리스 문자), `Arabic`(아라비아 문자), `Han`(한자) 등의 값을 가질 수 있습니다. Script 값의 전체 목록은 [여기서 볼 수 있습니다](https://en.wikipedia.org/wiki/Script_(Unicode)).
131
131
132
-
To look for characters in a given writing system we should use `pattern:Script=<value>`, e.g. for Cyrillic letters: `pattern:\p{sc=Cyrillic}`, for Chinese hieroglyphs: `pattern:\p{sc=Han}`, and so on:
132
+
특정 표기 체계의 문자를 찾으려면 `pattern:Script=<value>`를 사용해야 합니다. 키릴 문자는 `\p{sc=Cyrillic}`, 한자는 `pattern:\p{sc=Han}`로 검색하는 식으로 쓸 수 있습니다.
133
133
134
134
```js run
135
-
let regexp =/\p{sc=Han}/gu; //returns Chinese hieroglyphs
135
+
let regexp =/\p{sc=Han}/gu; //한자를 반환
136
136
137
137
let str =`Hello Привет 你好 123_456`;
138
138
139
139
alert( str.match(regexp) ); // 你,好
140
140
```
141
141
142
-
### Example: currency
142
+
### 예시: 통화
143
143
144
-
Characters that denote a currency, such as `$`, `€`, `¥`, have unicode property `pattern:\p{Currency_Symbol}`, the short alias:`pattern:\p{Sc}`.
144
+
`$`, `€`, `¥` 등 통화 단위를 나타내는 문자는 유니코드 프로퍼티 `pattern:\p{Currency_Symbol}`를 가지고 있습니다. 짧게는`pattern:\p{Sc}`로 사용합니다.
145
145
146
-
Let's use it to look for prices in the format "currency, followed by a digit":
146
+
`pattern:\p{Sc}`를 사용해서 '통화 단위 바로 뒤 숫자' 형태의 가격 표시를 찾아봅시다.
0 commit comments