2.7 KiB
2.7 KiB
id, title, challengeType, forumTopicId, localeTitle
id | title | challengeType | forumTopicId | localeTitle |
---|---|---|---|---|
587d7db7367417b2b2512b9d | Match Beginning String Patterns | 1 | 301349 | Сопоставление начальных шаблонов строк |
Description
caret
( ^
) внутри character set
чтобы создать negated character set
в форме [^thingsThatWillNotBeMatched]
. Вне character set
caret
используется для поиска шаблонов в начале строк. пусть firstString = "Ricky является первым и может быть найден.";
пусть firstRegex = / ^ Ricky /;
firstRegex.test (firstString);
// Возвращает true
let notFirst = «Теперь вы не можете найти Рики»;
firstRegex.test (notFirst);
// Возвращает false
Instructions
caret
в регулярном выражении, чтобы найти "Cal"
только в начале строки rickyAndCal
.
Tests
tests:
- text: Your regex should search for <code>"Cal"</code> 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 <code>"Cal"</code> at the beginning of the string.
testString: assert(calRegex.test("Cal and Ricky both like racing."));
- text: Your regex should not match <code>"Cal"</code> in the middle of a string.
testString: assert(!calRegex.test("Ricky and Cal both like racing."));
Challenge Seed
let rickyAndCal = "Cal and Ricky both like racing.";
let calRegex = /change/; // Change this line
let result = calRegex.test(rickyAndCal);
Solution
let rickyAndCal = "Cal and Ricky both like racing.";
let calRegex = /^Cal/; // Change this line
let result = calRegex.test(rickyAndCal);