3.6 KiB
3.6 KiB
id | title | challengeType | videoUrl | localeTitle |
---|---|---|---|---|
587d7db7367417b2b2512b9f | Match All Letters and Numbers | 1 | Corresponder todas as letras e números |
Description
[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 _] + /;Essas classes de caracteres de atalho também são conhecidas como
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
shorthand character classes
. Instructions
\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>"The five boxing wizards jump quickly."</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>"Pack my box with five dozen liquor jugs."</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>"How vexingly quick daft zebras jump!"</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>"123 456 7890 ABC def GHI jkl MNO pqr STU vwx YZ."</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