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's because by default a caret`pattern:^` only matches at the beginning of the text, and in the multiline mode -- at the start of any line.
35
+
이렇게 결과가 다른 것은 캐럿 기호`pattern:^`가 기본적으로는 텍스트의 시작 위치에만 대응하기 때문입니다. 여러 행 모드를 사용해야 모든 행의 시작 위치와 대응하죠.
36
36
37
37
```smart
38
-
"Start of a line" formally means "immediately after a line break": the test `pattern:^` in multiline mode matches at all positions preceeded by a newline character `\n`.
38
+
'행 시작'이라는 것은 엄밀히 말해서 '줄 바꿈 직후'를 의미합니다. 여러 행 모드에서 `pattern:^`을 사용한 검사는 줄 바꿈 문자 `\n` 바로 뒤 모든 위치와 일치합니다.
39
39
40
-
And at the text start.
40
+
텍스트의 시작 위치를 포함해서요.
41
41
```
42
42
43
-
## Searching at line end $
43
+
## $로 행 끝 검색하기
44
44
45
-
The dollar sign `pattern:$` behaves similarly.
45
+
달러 기호 `pattern:$`는 캐럿 기호와 비슷하게 동작합니다.
46
46
47
-
The regular expression `pattern:\d$` finds the last digit in every line
47
+
정규 표현식 `pattern:\d$`를 사용하면 행 끝에 있는 숫자를 전부 찾을 수 있습니다.
48
48
49
49
```js run
50
50
let str =`Winnie: 1
@@ -54,21 +54,21 @@ Eeyore: 3`;
54
54
alert( str.match(/\d$/gm) ); // 1,2,3
55
55
```
56
56
57
-
Without the flag `pattern:m`, the dollar `pattern:$` would only match the end of the whole text, so only the very last digit would be found.
57
+
`m` 플래그가 없으면 달러 기호 `pattern:$`는 전체 텍스트의 끝에만 일치하므로 가장 뒤에 있는 마지막 숫자만 찾게 됩니다.
58
58
59
59
```smart
60
-
"End of a line" formally means "immediately before a line break": the test `pattern:$` in multiline mode matches at all positions succeeded by a newline character `\n`.
60
+
'행 끝'이라는 것은 엄밀히 말해서 '줄 바꿈 직전'을 의미합니다. 여러 행 모드에서 `pattern:$`을 사용한 검사는 줄 바꿈 문자 `\n` 바로 앞의 모든 위치와 일치합니다.
61
61
62
-
And at the text end.
62
+
텍스트의 끝 위치를 포함해서요.
63
63
```
64
64
65
-
## Searching for \n instead of ^ $
65
+
## ^ $ 대신 \n 검색하기
66
66
67
-
To find a newline, we can use not only anchors `pattern:^`and `pattern:$`, but also the newline character `\n`.
67
+
줄 바꿈을 찾을 때는 앵커 `pattern:^``pattern:$`뿐 아니라 줄 바꿈 문자 `\n`을 사용할 수도 있습니다.
68
68
69
-
What's the difference? Let's see an example.
69
+
두 방법은 어떤 게 다를까요? 예시를 보죠.
70
70
71
-
Here we search for `pattern:\d\n` instead of `pattern:\d$`:
71
+
이번에는 `pattern:\d$` 대신 `pattern:\d\n`을 사용해 검색해봅시다.
72
72
73
73
```js run
74
74
let str =`Winnie: 1
@@ -78,10 +78,10 @@ Eeyore: 3`;
78
78
alert( str.match(/\d\n/gm) ); // 1\n,2\n
79
79
```
80
80
81
-
As we can see, there are 2 matches instead of 3.
81
+
일치하는 결과가 3개가 아니라 2개인 것을 확인할 수 있습니다.
82
82
83
-
That's because there's no newline after `subject:3`(there's text end though, so it matches `pattern:$`).
83
+
`subject:3`다음에 줄 바꿈이 없기 때문이죠. 텍스트의 끝이기 때문에 `pattern:$`에는 일치하지만요.
84
84
85
-
Another difference: now every match includes a newline character`match:\n`. Unlike the anchors `pattern:^``pattern:$`, that only test the condition (start/end of a line), `\n` is a character, so it becomes a part of the result.
85
+
차이점이 하나 더 있습니다. 일치 결과에 줄 바꿈 문자`match:\n`이 포함되어있습니다. 앵커 `pattern:^``pattern:$`는 행의 시작·끝이라는 조건만 검사하지만 `\n`은 문자이기 때문에 결과에 포함됩니다.
86
86
87
-
So, a `\n` in the pattern is used when we need newline characters in the result, while anchors are used to find something at the beginning/end of a line.
87
+
따라서 결과에 줄 바꿈 문자가 필요하다면 정규식 패턴에 `\n`을 사용합니다. 줄 바꿈 문자 없이 행의 시작·끝에 있는 문자만 찾고 싶을 때는 앵커를 사용합니다.
0 commit comments