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
An empty string is the only match: it starts and immediately finishes.
1
+
Uma string vazia é a única correspondência: Ela começa e imediatamente termina.
2
2
3
-
The task once again demonstrates that anchors are not characters, but tests.
3
+
Esta tarefa demostra novamente que âncoras não são caracteres, mas sim testes.
4
4
5
-
The string is empty`""`. The engine first matches the `pattern:^` (input start), yes it's there, and then immediately the end `pattern:$`, it's here too. So there's a match.
5
+
A string está vazia`""`. O interpretador primeiro encontra o padrão de início da entrada `pattern:^` (que sim, está lá), e então imediatamente o fim da entrada `pattern:$` (que também está). Temos uma correspondência.
The caret `pattern:^`and dollar`pattern:$`characters have special meaning in a regexp. They are called "anchors".
3
+
Os caracteres acento circunflexo `pattern:^`e cifrão`pattern:$`possuem um significado especial em expressões regulares. Eles são chamados de "âncoras".
4
4
5
-
The caret `pattern:^`matches at the beginning of the text, and the dollar`pattern:$`-- at the end.
5
+
O acento circunflexo `pattern:^`corresponde ao início da string, e o cifrão`pattern:$`ao final.
6
6
7
-
For instance, let's test if the text starts with `Mary`:
7
+
Neste exemplo, vamos testar se o texto começa com `Maria`:
8
8
9
9
```js run
10
-
let str1 ="Mary had a little lamb";
11
-
alert(/^Mary/.test(str1) ); // true
10
+
let str1 ="Maria tinha um cordeirinho";
11
+
alert(/^Maria/.test(str1) ); // true
12
12
```
13
13
14
-
The pattern`pattern:^Mary` means: "string start and then Mary".
14
+
O padrão`pattern:^Maria` quer dizer: "início da string, e então Maria"
15
15
16
-
Similar to this, we can test if the string ends with `snow` using`pattern:snow$`:
16
+
Da mesma maneira, podemos testar se a string termina com `neve` usando`pattern:neve$`:
17
17
18
18
```js run
19
-
let str1 ="its fleece was white as snow";
20
-
alert(/snow$/.test(str1) ); // true
19
+
let str1 ="Seu velo era branco como a neve";
20
+
alert(/neve$/.test(str1) ); // true
21
21
```
22
22
23
-
In these particular cases we could use string methods `startsWith/endsWith`instead. Regular expressions should be used for more complex tests.
23
+
Nesses casos em particular, poderíamos usar os métodos do objeto string `startsWith/endsWith`em seu lugar. Expressões regulares devem ser usadas para testes mais complexos.
24
24
25
-
## Testing for a full match
25
+
## Correspondendo com uma string inteira
26
26
27
-
Both anchors together `pattern:^...$`are often used to test whether or not a string fully matches the pattern. For instance, to check if the user input is in the right format.
27
+
Frequentemente, ambas as âncoras `pattern:^...$`são usadas juntas para verificar se uma string inteira corresponde ao padrão. Para confirmar, por exemplo, se a entrada do usuário está no formato correto.
28
28
29
-
Let's check whether or not a string is a time in `12:34` format. That is: two digits, then a colon, and then another two digits.
29
+
Vamos verificar se uma string é um horário no formato `12:34`. Isto é: dois dígitos, seguido de dois pontos (':'), e então mais dois dígitos.
30
30
31
-
In regular expressions language that's`pattern:\d\d:\d\d`:
31
+
Em expressões regulares, isso fica`pattern:\d\d:\d\d`:
Here the match for `pattern:\d\d:\d\d`must start exactly after the beginning of the text `pattern:^`, and the end `pattern:$` must immediately follow.
42
+
Nesse exemplo, a correspondência com o padrão `pattern:\d\d:\d\d`deve iniciar exatamente após o início da string `pattern:^`, e ser seguido imediatamente pelo fim da string `pattern:$`.
43
43
44
-
The whole string must be exactly in this format. If there's any deviation or an extra character, the result is`false`.
44
+
A string inteira deve obedecer exatamente a esse formato. Se houver qualquer desvio ou caractere adicional, o resultado será`false`.
45
45
46
-
Anchors behave differently if flag `pattern:m`is present. We'll see that in the next article.
46
+
Âncoras tem um comportamento diferente caso a flag `pattern:m`esteja presente. Veremos isso no próximo artigo.
47
47
48
-
```smart header="Anchors have\"zero width\""
49
-
Anchors `pattern:^` and `pattern:$` are tests. They have zero width.
48
+
```smart header="Âncoras tem\"largura zero\""
49
+
As âncoras `pattern:^` e `pattern:$` são verificações. Elas não possuem largura.
50
50
51
-
In other words, they do not match a character, but rather force the regexp engine to check the condition (text start/end).
51
+
Em outras palavras, elas não correspondem com um caractere, mas sim com uma posição, obrigando o interpretador regex a verificar a condição de início ou fim da string.
0 commit comments