2018-09-30 23:01:58 +01:00
---
id: 587d7db7367417b2b2512b9d
title: Match Beginning String Patterns
challengeType: 1
2019-08-05 09:17:33 -07:00
forumTopicId: 301349
2021-01-13 03:31:00 +01:00
dashedName: match-beginning-string-patterns
2018-09-30 23:01:58 +01:00
---
2020-11-27 19:02:05 +01:00
# --description--
2018-09-30 23:01:58 +01: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-11-27 19:02:05 +01: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.
2019-05-17 06:20:30 -07: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-11-27 19:02:05 +01:00
# --instructions--
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
Use the caret character in a regex to find `"Cal"` only in the beginning of the string `rickyAndCal` .
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
# --hints--
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
Your regex should search for `"Cal"` with a capital letter.
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
```js
assert(calRegex.source == '^Cal');
2018-09-30 23:01:58 +01:00
```
2020-11-27 19:02:05 +01:00
Your regex should not use any flags.
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
```js
assert(calRegex.flags == '');
```
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
Your regex should match `"Cal"` at the beginning of the string.
2018-09-30 23:01:58 +01:00
```js
2020-11-27 19:02:05 +01:00
assert(calRegex.test('Cal and Ricky both like racing.'));
2018-09-30 23:01:58 +01:00
```
2020-11-27 19:02:05 +01:00
Your regex should not match `"Cal"` in the middle of a string.
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
```js
assert(!calRegex.test('Ricky and Cal both like racing.'));
```
# --seed--
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
## --seed-contents--
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
```js
let rickyAndCal = "Cal and Ricky both like racing.";
let calRegex = /change/; // Change this line
let result = calRegex.test(rickyAndCal);
```
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
# --solutions--
2018-09-30 23:01:58 +01:00
```js
2019-05-03 03:05:26 -07:00
let rickyAndCal = "Cal and Ricky both like racing.";
let calRegex = /^Cal/; // Change this line
let result = calRegex.test(rickyAndCal);
2018-09-30 23:01:58 +01:00
```