freeCodeCamp/curriculum/challenges/portuguese/02-javascript-algorithms-an.../regular-expressions/match-all-letters-and-numbe...

3.6 KiB

id title challengeType videoUrl localeTitle
587d7db7367417b2b2512b9f Match All Letters and Numbers 1 Corresponder todas as letras e números

Description

Usando classes de caracteres, você conseguiu pesquisar todas as letras do alfabeto com [az] . Esse tipo de classe de caracteres é comum o suficiente para que haja um atalho para ele, embora inclua alguns caracteres extras também. A classe de caractere mais próxima em JavaScript para corresponder ao alfabeto é \w . Este atalho é igual a [A-Za-z0-9_] . Essa classe de caracteres corresponde a letras maiúsculas e minúsculas mais números. Note que esta classe de caracteres também inclui o caractere de sublinhado ( _ ).
let longHand = / [A-Za-z0-9 _] + /;
deixe shortHand = / \ w + /;
deixe números = "42";
deixe varNames = "important_var";
longHand.test (números); // Retorna true
shortHand.test (números); // Retorna true
longHand.test (varNames); // Retorna true
shortHand.test (varNames); // Retorna true
Essas classes de caracteres de atalho também são conhecidas como shorthand character classes .

Instructions

Use a classe de caractere abreviada \w para contar o número de caracteres alfanuméricos em várias aspas e cadeias de caracteres.

Tests

tests:
  - text: Seu regex deve usar o sinalizador global.
    testString: 'assert(alphabetRegexV2.global, "Your regex should use the global flag.");'
  - text: Seu regex deve usar o caractere abreviado
    testString: 'assert(/\\w/.test(alphabetRegexV2.source), "Your regex should use the shorthand character <code>\w</code> to match all characters which are alphanumeric.");'
  - text: Seu regex deve encontrar 31 caracteres alfanuméricos em <code>&quot;The five boxing wizards jump quickly.&quot;</code>
    testString: 'assert("The five boxing wizards jump quickly.".match(alphabetRegexV2).length === 31, "Your regex should find 31 alphanumeric characters in <code>"The five boxing wizards jump quickly."</code>");'
  - text: Seu regex deve encontrar 32 caracteres alfanuméricos em <code>&quot;Pack my box with five dozen liquor jugs.&quot;</code>
    testString: 'assert("Pack my box with five dozen liquor jugs.".match(alphabetRegexV2).length === 32, "Your regex should find 32 alphanumeric characters in <code>"Pack my box with five dozen liquor jugs."</code>");'
  - text: Seu regex deve encontrar 30 caracteres alfanuméricos em <code>&quot;How vexingly quick daft zebras jump!&quot;</code>
    testString: 'assert("How vexingly quick daft zebras jump!".match(alphabetRegexV2).length === 30, "Your regex should find 30 alphanumeric characters in <code>"How vexingly quick daft zebras jump!"</code>");'
  - text: Seu regex deve encontrar 36 caracteres alfanuméricos em <code>&quot;123 456 7890 ABC def GHI jkl MNO pqr STU vwx YZ.&quot;</code>
    testString: 'assert("123 456 7890 ABC def GHI jkl MNO pqr STU vwx YZ.".match(alphabetRegexV2).length === 36, "Your regex should find 36 alphanumeric characters in <code>"123 456 7890 ABC def GHI jkl MNO pqr STU vwx YZ."</code>");'

Challenge Seed

let quoteSample = "The five boxing wizards jump quickly.";
let alphabetRegexV2 = /change/; // Change this line
let result = quoteSample.match(alphabetRegexV2).length;

Solution

// solution required