2018-10-10 22:03:03 +00:00
---
id: 587d7db7367417b2b2512b9d
2021-02-06 04:42:36 +00:00
title: Match Beginning String Patterns
2018-10-10 22:03:03 +00:00
challengeType: 1
2020-08-04 07:14:01 +00:00
forumTopicId: 301349
2021-01-13 02:31:00 +00:00
dashedName: match-beginning-string-patterns
2018-10-10 22:03:03 +00:00
---
2020-12-16 07:37:30 +00:00
# --description--
2021-02-06 04:42:36 +00:00
Prior challenges showed that regular expressions can be used to look for a number of matches. They are also used to search for patterns in specific positions in strings.
2020-12-16 07:37:30 +00:00
2021-02-06 04:42:36 +00:00
In an earlier challenge, you used the 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.
2020-08-04 07:14:01 +00:00
```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
```
2020-12-16 07:37:30 +00:00
# --instructions--
2018-10-10 22:03:03 +00:00
2021-02-06 04:42:36 +00:00
Use the caret character in a regex to find `"Cal"` only in the beginning of the string `rickyAndCal` .
2018-10-10 22:03:03 +00:00
2020-12-16 07:37:30 +00:00
# --hints--
2018-10-10 22:03:03 +00:00
2021-02-06 04:42:36 +00:00
Your regex should search for `"Cal"` with a capital letter.
2018-10-10 22:03:03 +00:00
2020-12-16 07:37:30 +00:00
```js
assert(calRegex.source == '^Cal');
2018-10-10 22:03:03 +00:00
```
2021-02-06 04:42:36 +00:00
Your regex should not use any flags.
2018-10-10 22:03:03 +00:00
```js
2020-12-16 07:37:30 +00:00
assert(calRegex.flags == '');
2018-10-10 22:03:03 +00:00
```
2021-02-06 04:42:36 +00:00
Your regex should match `"Cal"` at the beginning of the string.
2018-10-10 22:03:03 +00:00
2020-12-16 07:37:30 +00:00
```js
assert(calRegex.test('Cal and Ricky both like racing.'));
```
2018-10-10 22:03:03 +00:00
2021-02-06 04:42:36 +00:00
Your regex should not match `"Cal"` in the middle of a string.
2018-10-10 22:03:03 +00:00
```js
2020-12-16 07:37:30 +00:00
assert(!calRegex.test('Ricky and Cal both like racing.'));
2018-10-10 22:03:03 +00:00
```
2020-08-04 07:14:01 +00:00
2021-01-13 02:31:00 +00:00
# --seed--
## --seed-contents--
```js
let rickyAndCal = "Cal and Ricky both like racing.";
let calRegex = /change/; // Change this line
let result = calRegex.test(rickyAndCal);
```
2020-12-16 07:37:30 +00:00
# --solutions--
2021-01-13 02:31:00 +00:00
```js
let rickyAndCal = "Cal and Ricky both like racing.";
let calRegex = /^Cal/; // Change this line
let result = calRegex.test(rickyAndCal);
```