2.7 KiB
2.7 KiB
id | title | challengeType | videoUrl | localeTitle |
---|---|---|---|---|
587d7db8367417b2b2512ba3 | Match Whitespace | 1 | Corresponder espaço em branco |
Description
\s
, que é um s
minúsculo. Esse padrão não apenas corresponde ao espaço em branco, mas também ao retorno de carro, à guia, ao feed de formulário e aos novos caracteres de linha. Você pode pensar nisso como semelhante à classe de caracteres [ \r\t\f\n\v]
. let whiteSpace = "Espaço em branco. Espaço em branco em todo lugar!"
deixe spaceRegex = / \ s / g;
whiteSpace.match (spaceRegex);
// Retorna ["", ""]
Instructions
countWhiteSpace
para procurar vários caracteres de espaço em branco em uma string. Tests
tests:
- text: Seu regex deve usar o sinalizador global.
testString: 'assert(countWhiteSpace.global, "Your regex should use the global flag.");'
- text: Seu regex deve usar o caractere abreviado
testString: 'assert(/\\s/.test(countWhiteSpace.source), "Your regex should use the shorthand character <code>\s</code> to match all whitespace characters.");'
- text: Seu regex deve encontrar oito espaços em <code>"Men are from Mars and women are from Venus."</code>
testString: 'assert("Men are from Mars and women are from Venus.".match(countWhiteSpace).length == 8, "Your regex should find eight spaces in <code>"Men are from Mars and women are from Venus."</code>");'
- text: 'Seu regex deve encontrar três espaços em <code>"Space: the final frontier."</code>'
testString: 'assert("Space: the final frontier.".match(countWhiteSpace).length == 3, "Your regex should find three spaces in <code>"Space: the final frontier."</code>");'
- text: Seu regex não deve encontrar espaços em <code>"MindYourPersonalSpace"</code>
testString: 'assert("MindYourPersonalSpace".match(countWhiteSpace) == null, "Your regex should find no spaces in <code>"MindYourPersonalSpace"</code>");'
Challenge Seed
let sample = "Whitespace is important in separating words";
let countWhiteSpace = /change/; // Change this line
let result = sample.match(countWhiteSpace);
Solution
// solution required