2.5 KiB
2.5 KiB
id | title | challengeType | videoUrl | localeTitle |
---|---|---|---|---|
587d7db7367417b2b2512b9d | Match Beginning String Patterns | 1 | Combinar Padrões de Cordas Iniciais |
Description
caret
( ^
) dentro de um character set
para criar um negated character set
no formato [^thingsThatWillNotBeMatched]
. Fora de um character set
, o caret
é usado para procurar padrões no início das seqüências de caracteres. deixe firstString = "Ricky é o primeiro e pode ser encontrado";
deixe firstRegex = / ^ Ricky /;
firstRegex.test (firstString);
// Retorna true
vamos notFirst = "Você não pode encontrar Ricky agora.";
firstRegex.test (notFirst);
// Retorna falso
Instructions
caret
em um regex para localizar "Cal"
apenas no início da string rickyAndCal
. Tests
tests:
- text: Seu regex deve procurar por <code>"Cal"</code> com uma letra maiúscula.
testString: 'assert(calRegex.source == "^Cal", "Your regex should search for <code>"Cal"</code> with a capital letter.");'
- text: Seu regex não deve usar sinalizadores.
testString: 'assert(calRegex.flags == "", "Your regex should not use any flags.");'
- text: Seu regex deve corresponder a <code>"Cal"</code> no início da string.
testString: 'assert(calRegex.test("Cal and Ricky both like racing."), "Your regex should match <code>"Cal"</code> at the beginning of the string.");'
- text: Seu regex não deve corresponder a <code>"Cal"</code> no meio de uma string.
testString: 'assert(!calRegex.test("Ricky and Cal both like racing."), "Your regex should not match <code>"Cal"</code> in the middle of a string.");'
Challenge Seed
let rickyAndCal = "Cal and Ricky both like racing.";
let calRegex = /change/; // Change this line
let result = calRegex.test(rickyAndCal);
Solution
// solution required