freeCodeCamp/curriculum/challenges/portuguese/02-javascript-algorithms-an.../regular-expressions/match-beginning-string-patt...

2.5 KiB
Raw Blame History

id title challengeType videoUrl localeTitle
587d7db7367417b2b2512b9d Match Beginning String Patterns 1 Combinar Padrões de Cordas Iniciais

Description

Desafios anteriores mostraram que expressões regulares podem ser usadas para procurar um número de correspondências. Eles também são usados para procurar padrões em posições específicas em strings. Em um desafio anterior, você usou o caractere 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

Use o caractere de caret em um regex para localizar "Cal" apenas no início da string rickyAndCal .

Tests

tests:
  - text: Seu regex deve procurar por <code>&quot;Cal&quot;</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>&quot;Cal&quot;</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>&quot;Cal&quot;</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