2021-06-15 07:49:18 +00:00
---
id: 587d7db8367417b2b2512ba0
2021-07-21 15:23:20 +00:00
title: Capturar tudo exceto letras e números
2021-06-15 07:49:18 +00:00
challengeType: 1
forumTopicId: 301353
dashedName: match-everything-but-letters-and-numbers
---
# --description--
2021-07-16 05:33:16 +00:00
Você aprendeu que você pode usar um atalho para capturar alfanuméricos `[A-Za-z0-9_]` usando `\w` . Você pode querer capturar exatamente o oposto disso.
2021-06-15 07:49:18 +00:00
2021-07-16 05:33:16 +00:00
Você pode capturar não-alfanuméricos usando `\W` ao invés de `\w` . Observe que o atalho usa uma maiúscula. Este atalho é o mesmo que escrever `[^A-Za-z0-9_]` .
2021-06-15 07:49:18 +00:00
```js
let shortHand = /\W/;
let numbers = "42%";
let sentence = "Coding!";
numbers.match(shortHand);
sentence.match(shortHand);
```
2021-07-16 05:33:16 +00:00
A primeira chamada a `match` retorna `["%"]` enquanto o segundo retorna `["!"]` .
2021-06-15 07:49:18 +00:00
# --instructions--
2021-07-16 05:33:16 +00:00
Use o atalho `\W` para contar o número de caracteres não-alfanuméricos em várias strings.
2021-06-15 07:49:18 +00:00
# --hints--
2021-07-16 05:33:16 +00:00
Sua regex deve usar a flag global.
2021-06-15 07:49:18 +00:00
```js
assert(nonAlphabetRegex.global);
```
2021-07-16 05:33:16 +00:00
Sua regex deve encontrar 6 caracteres não-alfanuméricos na string `The five boxing wizards jump quickly.` .
2021-06-15 07:49:18 +00:00
```js
assert(
'The five boxing wizards jump quickly.'.match(nonAlphabetRegex).length == 6
);
```
2021-07-16 05:33:16 +00:00
Sua regex deve usar o atalho que captura os caracteres não-alfanuméricos.
2021-06-15 07:49:18 +00:00
```js
assert(/\\W/.test(nonAlphabetRegex.source));
```
2021-07-16 05:33:16 +00:00
Sua regex deve encontrar 8 caracteres não-alfanuméricos na string `Pack my box with five dozen liquor jugs.`
2021-06-15 07:49:18 +00:00
```js
assert(
'Pack my box with five dozen liquor jugs.'.match(nonAlphabetRegex).length == 8
);
```
2021-07-16 05:33:16 +00:00
Sua regex deve encontrar 6 caracteres não-alfanuméricos na string `How vexingly quick daft zebras jump!`
2021-06-15 07:49:18 +00:00
```js
assert(
'How vexingly quick daft zebras jump!'.match(nonAlphabetRegex).length == 6
);
```
2021-07-16 05:33:16 +00:00
Sua regex deve encontrar 12 caracteres não-alfanuméricos na string `123 456 7890 ABC def GHI jkl MNO pqr STU vwx YZ.`
2021-06-15 07:49:18 +00:00
```js
assert(
'123 456 7890 ABC def GHI jkl MNO pqr STU vwx YZ.'.match(nonAlphabetRegex)
.length == 12
);
```
# --seed--
## --seed-contents--
```js
let quoteSample = "The five boxing wizards jump quickly.";
let nonAlphabetRegex = /change/; // Change this line
let result = quoteSample.match(nonAlphabetRegex).length;
```
# --solutions--
```js
let quoteSample = "The five boxing wizards_jump quickly.";
let nonAlphabetRegex = /\W/g; // Change this line
let result = quoteSample.match(nonAlphabetRegex).length;
```