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.
```js
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
```
caret
character in a regex to find "Cal"
only in the beginning of the string 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."));
```