caret
para procurar padrões no início das seqüências de caracteres. Há também uma maneira de procurar padrões no final das strings. Você pode pesquisar o final das strings usando o caractere de dollar sign
$
no final da regex. deixe theEnding = "Esta é uma história sem fim";
deixe storyRegex = / story $ /;
storyRegex.test (theEnding);
// Retorna true
deixe noEnding = "Às vezes uma história terá que terminar";
storyRegex.test (noEnding);
// Retorna falso
$
) para combinar com a string "caboose"
no final do caboose
string. "caboose"
com o cifrão $
anchor no seu regex.
testString: 'assert(lastRegex.source == "caboose$", "You should search for "caboose"
with the dollar sign $
anchor in your regex.");'
- text: Seu regex não deve usar sinalizadores.
testString: 'assert(lastRegex.flags == "", "Your regex should not use any flags.");'
- text: Você deve combinar "caboose"
no final da corda "The last car on a train is the caboose"
testString: 'assert(lastRegex.test("The last car on a train is the caboose"), "You should match "caboose"
at the end of the string "The last car on a train is the caboose"
");'
```