* fix(curriculum): tests quotes * fix(curriculum): fill seed-teardown * fix(curriculum): fix tests and remove unneeded seed-teardown
2.3 KiB
2.3 KiB
id, title, challengeType
id | title | challengeType |
---|---|---|
587d7db7367417b2b2512b9d | Match Beginning String Patterns | 1 |
Description
caret
character (^
) inside a character set
to create a negated character set
in the form [^thingsThatWillNotBeMatched]
. Outside of a character set
, the caret
is used to search for patterns at the beginning of strings.
let firstString = "Ricky is first and can be found.";
let firstRegex = /^Ricky/;
firstRegex.test(firstString);
// Returns true
let notFirst = "You can't find Ricky now.";
firstRegex.test(notFirst);
// Returns false
Instructions
caret
character in a regex to find "Cal"
only in the beginning of the string rickyAndCal
.
Tests
tests:
- text: Your regex should search for <code>"Cal"</code> with a capital letter.
testString: assert(calRegex.source == "^Cal", 'Your regex should search for <code>"Cal"</code> with a capital letter.');
- text: Your regex should not use any flags.
testString: assert(calRegex.flags == "", 'Your regex should not use any 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."), 'Your regex should match <code>"Cal"</code> at the beginning of the string.');
- 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."), '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