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
caret
em um regex para localizar "Cal"
apenas no início da string rickyAndCal
. "Cal"
com uma letra maiúscula.
testString: 'assert(calRegex.source == "^Cal", "Your regex should search for "Cal"
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 "Cal"
no início da string.
testString: 'assert(calRegex.test("Cal and Ricky both like racing."), "Your regex should match "Cal"
at the beginning of the string.");'
- text: Seu regex não deve corresponder a "Cal"
no meio de uma string.
testString: 'assert(!calRegex.test("Ricky and Cal both like racing."), "Your regex should not match "Cal"
in the middle of a string.");'
```