2.7 KiB
2.7 KiB
id | title | challengeType | videoUrl | localeTitle |
---|---|---|---|---|
587d7db9367417b2b2512ba4 | Match Non-Whitespace Characters | 1 | Corresponder Personagens Não-Brancos |
Description
\s
, com um s
minúsculo. Você também pode pesquisar tudo, exceto o espaço em branco. Procure por espaços não brancos usando \S
, que é um s
maiúsculo. Esse padrão não corresponderá a espaço em branco, retorno de carro, guia, feed de formulário e novos caracteres de linha. Você pode pensar que é semelhante à classe de caracteres [^ \r\t\f\n\v]
. let whiteSpace = "Espaço em branco. Espaço em branco em todo lugar!"
deixe nonSpaceRegex = / \ S / g;
whiteSpace.match (nonSpaceRegex) .length; // retorna 32
Instructions
countNonWhiteSpace
da regex para procurar vários caracteres que não sejam espaços em branco em uma string. Tests
tests:
- text: Seu regex deve usar o sinalizador global.
testString: 'assert(countNonWhiteSpace.global, "Your regex should use the global flag.");'
- text: Seu regex deve usar o caractere abreviado
testString: 'assert(/\\S/.test(countNonWhiteSpace.source), "Your regex should use the shorthand character <code>\S/code> to match all non-whitespace characters.");'
- text: Seu regex deve encontrar 35 não-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(countNonWhiteSpace).length == 35, "Your regex should find 35 non-spaces in <code>"Men are from Mars and women are from Venus."</code>");'
- text: 'Seu regex deve encontrar 23 espaços diferentes em <code>"Space: the final frontier."</code>'
testString: 'assert("Space: the final frontier.".match(countNonWhiteSpace).length == 23, "Your regex should find 23 non-spaces in <code>"Space: the final frontier."</code>");'
- text: Seu regex deve encontrar 21 não espaços em <code>"MindYourPersonalSpace"</code>
testString: 'assert("MindYourPersonalSpace".match(countNonWhiteSpace).length == 21, "Your regex should find 21 non-spaces in <code>"MindYourPersonalSpace"</code>");'
Challenge Seed
let sample = "Whitespace is important in separating words";
let countNonWhiteSpace = /change/; // Change this line
let result = sample.match(countNonWhiteSpace);
Solution
// solution required