2021-06-15 00:49:18 -07:00
---
id: 587d7db7367417b2b2512b9f
2021-07-21 20:53:20 +05:30
title: Capturar todas as letras e números
2021-06-15 00:49:18 -07:00
challengeType: 1
forumTopicId: 301346
dashedName: match-all-letters-and-numbers
---
# --description--
2021-07-16 11:03:16 +05:30
Ao escrever `[a-z]` você foi capaz de capturar todas as letras do alfabeto. Essa classe de caracteres é tão comum que existe uma forma reduzida de escrevê-la. Mas essa forma inclui alguns caracteres a mais.
2021-06-15 00:49:18 -07:00
2021-07-16 11:03:16 +05:30
Em JavaScript, você pode usar `\w` para capturar todas as letras do alfabeto. Isso é equivalente à classe de caracteres `[A-Za-z0-9_]` . Ela captura números e letras, tanto maiúsculas quanto minúsculas. Note que o underline (`_` ) também é incluído nela.
2021-06-15 00:49:18 -07:00
```js
let longHand = /[A-Za-z0-9_]+/;
let shortHand = /\w+/;
let numbers = "42";
let varNames = "important_var";
longHand.test(numbers);
shortHand.test(numbers);
longHand.test(varNames);
shortHand.test(varNames);
```
2021-07-16 11:03:16 +05:30
As quatro chamadas a `test` retornam `true` .
2021-06-15 00:49:18 -07:00
2021-07-16 11:03:16 +05:30
Essas formas reduzidas de classes de caracteres podem ser chamadas de < dfn > atalhos< / dfn > .
2021-06-15 00:49:18 -07:00
# --instructions--
2021-07-16 11:03:16 +05:30
Use o atalho `\w` para contar o número de caracteres alfanuméricos em várias strings.
2021-06-15 00:49:18 -07:00
# --hints--
2021-07-30 23:57:21 +09:00
A regex deve usar a flag global.
2021-06-15 00:49:18 -07:00
```js
assert(alphabetRegexV2.global);
```
2021-07-30 23:57:21 +09:00
A regex deve usar o atalho `\w` para capturar todos os caracteres alfanuméricos.
2021-06-15 00:49:18 -07:00
```js
assert(/\\w/.test(alphabetRegexV2.source));
```
2021-07-30 23:57:21 +09:00
A regex deve encontrar 31 caracteres alfanuméricos na string `The five boxing wizards jump quickly.`
2021-06-15 00:49:18 -07:00
```js
assert(
'The five boxing wizards jump quickly.'.match(alphabetRegexV2).length === 31
);
```
2021-07-30 23:57:21 +09:00
A regex deve encontrar 32 caracteres alfanuméricos na string `Pack my box with five dozen liquor jugs.`
2021-06-15 00:49:18 -07:00
```js
assert(
'Pack my box with five dozen liquor jugs.'.match(alphabetRegexV2).length ===
32
);
```
2021-07-30 23:57:21 +09:00
A regex deve encontrar 30 caracteres alfanuméricos na string `How vexingly quick daft zebras jump!`
2021-06-15 00:49:18 -07:00
```js
assert(
'How vexingly quick daft zebras jump!'.match(alphabetRegexV2).length === 30
);
```
2021-07-30 23:57:21 +09:00
A regex deve encontrar 36 caracteres alfanuméricos na string `123 456 7890 ABC def GHI jkl MNO pqr STU vwx YZ.`
2021-06-15 00:49:18 -07:00
```js
assert(
'123 456 7890 ABC def GHI jkl MNO pqr STU vwx YZ.'.match(alphabetRegexV2)
.length === 36
);
```
# --seed--
## --seed-contents--
```js
let quoteSample = "The five boxing wizards jump quickly.";
let alphabetRegexV2 = /change/; // Change this line
let result = quoteSample.match(alphabetRegexV2).length;
```
# --solutions--
```js
let quoteSample = "The five boxing wizards jump quickly.";
let alphabetRegexV2 = /\w/g; // Change this line
let result = quoteSample.match(alphabetRegexV2).length;
```