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
That was a character class for digits. There are other character classes as well.
36
+
여기까지 숫자를 찾는 문자 클래스였습니다. 물론 다른 문자 클래스도 있습니다.
37
37
38
-
Most used are:
38
+
자주 사용하는 문자 클래스에는 다음 클래스가 있습니다.
39
39
40
-
`pattern:\d` ("d" is from "digit")
41
-
: A digit: a character from `0` to `9`.
40
+
`pattern:\d` ('digit(숫자)'의 'd')
41
+
: 숫자: `0`에서 `9` 사이의 문자
42
42
43
-
`pattern:\s` ("s" is from "space")
44
-
: A space symbol: includes spaces, tabs `\t`, newlines `\n` and few other rare characters, such as `\v`, `\f` and `\r`.
43
+
`pattern:\s` ('space(공백)'의 's')
44
+
: 스페이스, 탭(`\t`), 줄 바꿈(`\n`)을 비롯하여 아주 드물게 쓰이는 `\v`, `\f`, `\r` 을 포함하는 공백 기호
45
45
46
-
`pattern:\w` ("w" is from "word")
47
-
: A "wordly" character: either a letter of Latin alphabet or a digit or an underscore `_`. Non-Latin letters (like cyrillic or hindi) do not belong to `pattern:\w`.
46
+
`pattern:\w` ('word(단어)'의 'w')
47
+
: '단어에 들어가는' 문자로 라틴 문자나 숫자, 밑줄 `_`을 포함합니다. 키릴 문자나 힌디 문자같은 비 라틴 문자는 `pattern:\w`에 포함되지 않습니다.
48
48
49
-
For instance,`pattern:\d\s\w` means a "digit" followed by a "space character" followed by a "wordly character", such as `match:1 a`.
49
+
예를 들어`pattern:\d\s\w`는 `match:1 a`처럼 '숫자' 뒤에 '공백 문자' 뒤에 '단어에 들어가는 문자'를 의미합니다.
50
50
51
-
**A regexp may contain both regular symbols and character classes.**
51
+
**정규 표현식에 일반 기호와 문자 클래스를 같이 사용할 수 있습니다.**
52
52
53
-
For instance, `pattern:CSS\d` matches a string `match:CSS`with a digit after it:
53
+
예시로, `pattern:CSS\d`는 `match:CSS`뒤에 숫자 하나가 있는 문자열과 일치합니다.
54
54
55
55
```js run
56
56
let str ="Is there CSS4?";
57
-
let regexp =/CSS\d/
57
+
let regexp =/CSS\d/;
58
58
59
59
alert( str.match(regexp) ); // CSS4
60
60
```
61
61
62
-
Also we can use many character classes:
62
+
또한 문자 클래스를 여러 개 사용할 수도 있습니다.
63
63
64
64
```js run
65
65
alert( "I love HTML5!".match(/\s\w\w\w\w\d/) ); // ' HTML5'
66
66
```
67
67
68
-
The match (each regexp character class has the corresponding result character):
68
+
일치 결과(각각의 문자 클래스에 글자 하나씩 일치):
69
69
70
70

71
71
72
-
## Inverse classes
72
+
## 반대 클래스
73
73
74
-
For every character class there exists an "inverse class", denoted with the same letter, but uppercased.
74
+
모든 문자 클래스에는 '반대 클래스'가 있습니다. 같은 글자로 표기하지만 대문자로 사용합니다.
75
75
76
-
The "inverse" means that it matches all other characters, for instance:
76
+
'반대'란 다음 예시들처럼 해당 문자를 제외한 모든 문자에 일치한다는 뜻입니다.
77
77
78
78
`pattern:\D`
79
-
: Non-digit: any character except `pattern:\d`, for instance a letter.
79
+
: 숫자가 아닌 문자: `pattern:\d`와 일치하지 않는 일반 글자 등의 모든 문자
80
80
81
81
`pattern:\S`
82
-
: Non-space: any character except `pattern:\s`, for instance a letter.
82
+
: 공백이 아닌 문자: `pattern:\s`와 일치하지 않는 일반 글자 등의 모든 문자
83
83
84
84
`pattern:\W`
85
-
: Non-wordly character: anything but`pattern:\w`, e.g a non-latin letter or a space.
85
+
: 단어에 들어가지 않는 문자:`pattern:\w`와 일치하지 않는 비 라틴 문자나 공백 등의 모든 문자
86
86
87
-
In the beginning of the chapter we saw how to make a number-only phone number from a string like `subject:+7(903)-123-45-67`: find all digits and join them.
87
+
이번 챕터의 첫 부분에서 `subject:+7(903)-123-45-67`같은 문자열에서 숫자를 모두 찾아 합쳐서 숫자만 남은 전화번호를 만드는 방법을 알아봤습니다.
The pattern `pattern:[\s\S]` literally says: "a space character OR not a space character". In other words, "anything". We could use another pair of complementary classes, such as `pattern:[\d\D]`, that doesn't matter. Or even the `pattern:[^]` -- as it means match any character except nothing.
156
+
`pattern:[\s\S]` 패턴의 문자 그대로의 뜻은 '공백 문자 또는 공백 문자가 아닌 문자'입니다. 결국은 모든 문자라는 뜻이죠. 이런 식으로 반대되는 클래스를 같이 사용하는 다른 패턴, 예를 들면 `pattern:[\d\D]`을 사용할 수도 있습니다. 또는 아무 문자도 없는 경우를 제외하는 `pattern:[^]`을 사용할 수도 있습니다.
157
157
158
-
Also we can use this trick if we want both kind of "dots" in the same pattern: the actual dot `pattern:.` behaving the regular way ("not including a newline"), and also a way to match "any character" with `pattern:[\s\S]` or alike.
158
+
그리고 이 기술을 이용해 같은 정규 표현식 안에서 점의 두 가지 패턴을 모두 사용할 수 있습니다. 줄 바꿈 문자를 포함하지 않는 원래의 점 `pattern:.`과 모든 문자와 일치하는 `pattern:[\s\S]`같은 패턴을 동시에 사용 가능합니다.
159
159
````
160
160
161
-
````warn header="Pay attention to spaces"
162
-
Usually we pay little attention to spaces. For us strings `subject:1-5` and `subject:1 - 5` are nearly identical.
161
+
````warn header="공백을 주의하세요."
162
+
사람은 보통 공백을 크게 의식하지 않습니다. 사람에게는 문자열 `subject:1-5`나 `subject:1 - 5`나 거의 같으니까요.
163
163
164
-
But if a regexp doesn't take spaces into account, it may fail to work.
164
+
하지만 정규 표현식에서 공백을 염두하지 않으면 원하는 결과를 얻지 못할 수 있습니다.
165
165
166
-
Let's try to find digits separated by a hyphen:
166
+
하이픈으로 구분된 숫자를 찾아봅시다.
167
167
168
168
```js run
169
-
alert( "1 - 5".match(/\d-\d/) ); // null, no match!
169
+
alert( "1 - 5".match(/\d-\d/) ); // null, 일치 결과 없음!
170
170
```
171
171
172
-
Let's fix it adding spaces into the regexp `pattern:\d - \d`:
172
+
정규 표현식에 공백을 넣어서 `pattern:\d - \d`로 바꿔봅시다.
173
173
174
174
```js run
175
-
alert( "1 - 5".match(/\d - \d/) ); // 1 - 5, now it works
176
-
// or we can use \s class:
177
-
alert( "1 - 5".match(/\d\s-\s\d/) ); // 1 - 5, also works
175
+
alert( "1 - 5".match(/\d - \d/) ); // 1 - 5, 이제 제대로 되네요.
**A space is a character. Equal in importance with any other character.**
180
+
**공백 역시 문자입니다. 다른 문자만큼이나 중요합니다.**
181
181
182
-
We can't add or remove spaces from a regular expression and expect to work the same.
182
+
정규 표현식에 공백을 추가하거나 지우면 다르게 작동합니다.
183
183
184
-
In other words, in a regular expression all characters matter, spaces too.
184
+
즉, 정규 표현식에서는 모든 문자가 중요합니다. 공백도 마찬가지로요.
185
185
````
186
186
187
-
## Summary
187
+
## 요약
188
188
189
-
There exist following character classes:
189
+
문자 클래스에는 다음 클래스들이 있습니다.
190
190
191
-
-`pattern:\d` -- digits.
192
-
-`pattern:\D` -- non-digits.
193
-
-`pattern:\s` -- space symbols, tabs, newlines.
194
-
-`pattern:\S` -- all but `pattern:\s`.
195
-
-`pattern:\w` -- Latin letters, digits, underscore`'_'`.
196
-
-`pattern:\W` -- all but `pattern:\w`.
197
-
-`pattern:.` -- any character if with the regexp `'s'`flag, otherwise any except a newline `\n`.
191
+
-`pattern:\d` -- 숫자
192
+
-`pattern:\D` -- 숫자가 아닌 문자
193
+
-`pattern:\s` -- 스페이스, 탭, 줄 바꿈 문자
194
+
-`pattern:\S` -- `pattern:\s`를 제외한 모든 문자
195
+
-`pattern:\w` -- 라틴 문자, 숫자, 밑줄`'_'`
196
+
-`pattern:\W` -- `pattern:\w`를 제외한 모든 문자
197
+
-`pattern:.` -- 정규 표현식 `'s'`플래그가 있으면 모든 문자, 없으면 줄 바꿈 `\n`을 제외한 모든 문자
198
198
199
-
...But that's not all!
199
+
하지만 이게 전부가 아닙니다!
200
200
201
-
Unicode encoding, used by JavaScript for strings, provides many properties for characters, like: which language the letter belongs to (if it's a letter) it is it a punctuation sign, etc.
201
+
자바스크립트에서 문자열에 사용하는 유니코드 인코딩은 문자에 여러 프로퍼티를 제공합니다. 어떤 언어에 속하는 글자인지 또는 글자가 아닌 구두점인지 알려주는 프로퍼티처럼요.
202
202
203
-
We can search by these properties as well. That requires flag `pattern:u`, covered in the next article.
203
+
이런 프로퍼티를 기준으로 문자를 찾을 수도 있습니다. `pattern:u` 플래그를 사용하면 되는데요. 다음 글에서 알아보도록 하죠.
0 commit comments