caret
( ^
) внутри character set
чтобы создать negated character set
в форме [^thingsThatWillNotBeMatched]
. Вне character set
caret
используется для поиска шаблонов в начале строк. пусть firstString = "Ricky является первым и может быть найден.";
пусть firstRegex = / ^ Ricky /;
firstRegex.test (firstString);
// Возвращает true
let notFirst = «Теперь вы не можете найти Рики»;
firstRegex.test (notFirst);
// Возвращает false
caret
в регулярном выражении, чтобы найти "Cal"
только в начале строки rickyAndCal
.
"Cal"
with a capital letter.
testString: assert(calRegex.source == "^Cal");
- text: Your regex should not use any flags.
testString: assert(calRegex.flags == "");
- text: Your regex should match "Cal"
at the beginning of the string.
testString: assert(calRegex.test("Cal and Ricky both like racing."));
- text: Your regex should not match "Cal"
in the middle of a string.
testString: assert(!calRegex.test("Ricky and Cal both like racing."));
```