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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
That was a character class for digits. There are other characterclassesas well.
Essa era uma classe de caracteres para dígitos. Existem outrasclassesde caracteres.
Most used are:
As mais usadas são:
`pattern:\d` ("d"is from "digit")
:A digit: a character from `0`to `9`.
`padrão:\d` ("d"é de "digit")
:Um dígito: um caractere de `0`a `9`.
`pattern:\s` ("s"is from "space")
:A space symbol: includes spaces, tabs `\t`,newlines`\n`and few other rare characters, such as`\v`, `\f`and `\r`.
`padrão:\s` ("s"é de "space")
:Um símbolo de espaço: inclui espaços, tabulações `\t`,novas linhas`\n`e alguns outros caracteres raros, como`\v`, `\f`e `\r`.
`pattern:\w` ("w"is from "word")
: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`.
`padrão:\w` ("w"é de "word" (*palavra*))
:Um caractere de texto: uma letra do alfabeto latino ou um dígito ou um sublinhado`_`.Letras não latinas (como cirílico ou hindu) não pertencem ao `padrão:\w`.
For instance, `pattern:\d\s\w`means a "digit" followed by a "space character" followed by a "wordly character",such as `match:1 a`.
Por exemplo, `padrão:\d\s\w`significa um "dígito" seguido de um "caractere de espaço" seguido de um "caractere de texto",como `correspondência:1 a`.
**A regexpmay contain both regular symbols and character classes.**
**Uma regexppode conter símbolos regulares e classes de caracteres.**
For instance, `pattern:CSS\d`matches a string `match:CSS`with a digit after it:
Por exemplo, `padrão:CSS\d`corresponde aumastring `correspondência:CSS`com um dígito a seguir:
```js run
let str = "Is there CSS4?";
let str = "Existe CSS4?";
let regexp = /CSS\d/
alert( str.match(regexp) ); // CSS4
```
Also we can use many character classes:
Também podemos usar muitas classes de caracteres:
```js run
alert( "I love HTML5!".match(/\s\w\w\w\w\d/) ); // ' HTML5'
alert( "Eu amo HTML5!".match(/\s\w\w\w\w\d/) ); // ' HTML5'
```
The match (each regexp character class has the corresponding result character):
A correspondência (cada classe de caracteres regexp possui o caractere de resultado correspondente):

##Inverse classes
##Classes inversas
For every character class there exists an "inverse class",denoted with the same letter, but uppercased.
Para cada classe de caracteres existe uma "classe inversa",denotada com a mesma letra, mas em maiúsculas.
The "inverse" means that it matches all other characters, for instance:
O "inverso" significa que ele corresponde a todos os outros caracteres, por exemplo:
`pattern:\D`
:Non-digit: any character except `pattern:\d`,for instance a letter.
`padrão:\D`
:Não-dígito: qualquer caractere, exceto `padrão:\d`,por exemplo, uma letra.
`pattern:\S`
:Non-space: any character except `pattern:\s`,for instance a letter.
`padrão:\S`
:Não-espaço: qualquer caractere, exceto `padrão:\s`,por exemplo, uma letra.
`pattern:\W`
:Non-wordly character: anything but `pattern:\w`,e.g a non-latin letter or a space.
`padrão:\W`
:Caractere não verbal: qualquer coisa, exceto `padrão:\w`,por exemplo, uma letra não latina ou um espaço.
In the beginning of the chapter we saw how to make a number-only phone number from astringlike `subject:+7(903)-123-45-67`:find all digits and join them.
No início do capítulo, vimos como criar um número de telefone somente com números a partir de umastringcomo `subject:+7(903)-123-45-67`:encontre todos os dígitos e os junte.
An alternative, shorter way is to find non-digits `pattern:\D`and remove them from the string:
Uma maneira alternativa e mais curta é encontrar não-dígitos `padrão:\D`e removê-los da string:
```js run
let str = "+7(903)-123-45-67";
alert( str.replace(/\D/g, "") ); // 79031234567
```
##A dot is "any character"
##Um ponto é "qualquer caractere"
A dot `pattern:.`is a special character class that matches "any character except a newline".
Um ponto `padrão:.`é uma classe de caracteres especial que corresponde a "qualquer caractere, exceto uma nova linha".
For instance:
Por exemplo:
```js run
alert( "Z".match(/./) ); // Z
```
Or in the middle of a regexp:
Ou no meio de uma regexp:
```js run
let regexp = /CS.4/;
alert( "CSS4".match(regexp) ); // CSS4
alert( "CS-4".match(regexp) ); // CS-4
alert( "CS 4".match(regexp) ); // CS 4 (space is also a character)
alert( "CS 4".match(regexp) ); // CS 4 (o espaço é também um caractere)
```
Please note that a dot means "any character",but not the "absence of a character".There must be a character to match it:
Observe que um ponto significa "qualquer caractere",mas não a "ausência de um caractere".Deve haver um caractere para corresponder a ele:
```js run
alert( "CS4".match(/CS.4/) ); // null,no match because there's no character for the dot
alert( "CS4".match(/CS.4/) ); // null,sem correspondência porque não há caractere para o ponto
```
###Dot as literally any character with"s" flag
###Ponto como literalmente qualquer caractere com a flag"s"
By default, a dot doesn't match the newline character `\n`.
Por padrão, um ponto não corresponde ao caractere de nova linha `\n`.
For instance, the regexp `pattern:A.B`matches `match:A`, and then `match:B`with any character between them, except a newline `\n`:
Por exemplo, a regexp `padrão:A.B`corresponde `corresponde:A` e, em seguida, `corresponde:B`com qualquer caractere entre eles, exceto uma nova linha `\n`:
```js run
alert( "A\nB".match(/A.B/) ); // null (no match)
alert( "A\nB".match(/A.B/) ); // null (sem correspondência)
```
There are many situations when we'd like a dot to mean literally "any character",newline included.
Há muitas situações em que gostaríamos que um ponto significasse literalmente "qualquer caractere",incluindo a nova linha.
That's whatflag `pattern:s`does. If a regexphas it, then a dot `pattern:.`matches literally any character:
É o que aflag `padrão:s`faz. Se uma regexpa possui, então um ponto `padrão:.`corresponde literalmente a qualquer caractere:
Luckily, there's an alternative, that works everywhere. We can use aregexplike `pattern:[\s\S]`to match "any character" (this pattern will be covered in the article <info:regexp-character-sets-and-ranges>).
Felizmente, há uma alternativa, que funciona em qualquer lugar. Podemos usar umaregexpcomo `padrão:[\s\S]`para corresponder a "qualquer caractere" (este padrão irá ser estudado no artigo <info:regexp-character-sets-and-ranges>).
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 complementaryclasses, such as `pattern:[\d\D]`,that doesn't matter. Or even the `pattern:[^]` --as it means match any character except nothing.
O padrão `padrão:[\s\S]`diz literalmente: "um caractere de espaço OU não um caractere de espaço".Em outras palavras, "qualquer coisa".Poderíamos usar outro par declasses complementares, como `padrão:[\d\D]`,que não importa. Ou mesmo o padrão `padrão:[^]` --pois significa corresponder a qualquer caractere, exceto nada.
Also we can use this trick if we want both kind of "dots" in the same pattern: the actual dot `pattern:.`behaving theregularway ("not including a newline"), and also a way to match "any character" with `pattern:[\s\S]`or alike.
Também podemos usar esse truque se quisermos os dois tipos de "pontos" no mesmo padrão: o ponto real `padrão:.`comportando-se da maneiraregular("não incluindo uma nova linha") e também uma maneira de combinar "qualquer caractere" com `padrão:[\s\S]`ou similar.
````
````warn header="Pay attention to spaces"
Usually we pay little attention to spaces. For usstrings `subject:1-5`and `subject:1 - 5`are nearly identical.
````warn header="Preste atenção aos espaços"
Geralmente prestamos pouca atenção aos espaços. Para nós, asstrings `sujeito:1-5`e `sujeito:1 - 5`são quase idênticas.
But if a regexpdoesn't take spaces into account, it may fail to work.
Mas se uma regexpnão leva em consideração os espaços, ela pode falhar.
Let's try to find digits separated by a hyphen:
Vamos tentar encontrar dígitos separados por um hífen:
- `padrão:.` --qualquer caractere se estiver com a flagregexp `'s' `; caso contrário, qualquer um, exceto uma nova linha `\n`.
...But that's not all!
...Mas isso não é tudo!
Unicode encoding, used by JavaScriptfor strings,provides many properties for characters, like: which language the letter belongs to (if it's a letter),is it a punctuation sign, etc.
A codificação Unicode, usada pelo JavaScriptpara strings,fornece muitas propriedades para caracteres, como: a qual idioma a letra pertence (se for uma letra),é um sinal de pontuação, etc.
We can search by these properties as well. That requiresflag `pattern:u`,covered in the next article.
Também podemos pesquisar por essas propriedades. Isso requer aflag `padrão:u`,abordada no próximo artigo.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.