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
+
Isso acontece porque por padrão, o acento circunflexo `pattern:^`corresponde apenas com o começo da string -- e no modo multilinha no começo de cada linha.
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 preceded by a newline character `\n`.
39
-
40
-
And at the text start.
38
+
Formalmente, "começo de linha" quer dizer "imediatamente após uma quebra de linha": o teste `pattern:^` no modo multilinha corresponde a todas as posições precedidas por um caractere de nova linha `\n`, bem como o início da string como um todo.
41
39
```
42
40
43
-
## Searching at line end $
41
+
## Busca no fim da linha $
44
42
45
-
The dollar sign `pattern:$`behaves similarly.
43
+
O cifrão `pattern:$`se comporta de maneira similar.
46
44
47
-
The regular expression `pattern:\d$`finds the last digit in every line
45
+
A expressão regular `pattern:\d$`corresponde ao último dígito de cada linha
48
46
49
47
```js run
50
48
let str =`Winnie: 1
@@ -54,21 +52,19 @@ Eeyore: 3`;
54
52
console.log( str.match(/\d$/gm) ); // 1,2,3
55
53
```
56
54
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.
55
+
Sem a opção`pattern:m`, o cifrão`pattern:$`corresponde apenas ao fim da string inteira, então apenas o último dígito seria encontrado.
58
56
59
57
```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`.
61
-
62
-
And at the text end.
58
+
Formalmente, "fim de linha" quer dizer "imediatamente antes de uma quebra de linha": o teste `pattern:$` no modo multilinha corresponde a todas as posições sucedidas por um caractere de nova linha `\n`, bem como o fim da string como um todo.
63
59
```
64
60
65
-
## Searching for \n instead of ^ $
61
+
## Busca por \n ao invés de ^ e $
66
62
67
-
To find a newline, we can use not only anchors`pattern:^`and`pattern:$`, but also the newline character`\n`.
63
+
Para encontrar uma quebra de linha, podemos usar não apenas as âncoras`pattern:^`e`pattern:$`, mas também o caractere de nova linha`\n`.
68
64
69
-
What's the difference? Let's see an example.
65
+
Qual a diferença? Vejamos um exemplo.
70
66
71
-
Here we search for`pattern:\d\n`instead of`pattern:\d$`:
Como podemos ver, temos duas correspondências ao invés de 3
82
78
83
-
That's because there's no newline after `subject:3` (there's text end though, so it matches `pattern:$`).
79
+
Isso ocorre porque não há uma quebra de linha após o `subject:3` (Mas temos o fim da string, então ele corresponde com o `pattern:$`)
84
80
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.
81
+
Outra diferença: Agora cada correspondência inclui um caractere de nova linha `match:\n`. Diferentemente das âncoras`pattern:^`e `pattern:$`, que testam apenas a condição (início ou fim de uma linha), `\n`é um caractere, então ele se torna parte do resultado.
86
82
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.
83
+
Dessa forma, usamos o `\n`no padrão quando precisamos de caracteres de nova linha no resultado, e usamos âncoras quando precisamos buscar algo no começo ou final de uma linha.
0 commit comments