2018-10-12 15:37:13 -04:00
|
|
|
---
|
|
|
|
title: Match Beginning String Patterns
|
|
|
|
---
|
2019-07-24 00:59:27 -07:00
|
|
|
# Match Beginning String Patterns
|
2018-10-12 15:37:13 -04:00
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
---
|
|
|
|
## Problem Explanation
|
2018-10-12 15:37:13 -04:00
|
|
|
Use the caret character in a regex to find "Cal" only in the beginning of the string rickyAndCal.
|
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
|
|
|
|
---
|
|
|
|
## Hints
|
|
|
|
|
|
|
|
### Hint 1
|
2018-10-12 15:37:13 -04:00
|
|
|
Try surrounding your regexp in slashes
|
|
|
|
```javascript
|
2019-07-24 00:59:27 -07:00
|
|
|
let testExp = /^test/;
|
2018-10-12 15:37:13 -04:00
|
|
|
// returns true or false depending on whether test is found in the beginning of the string
|
|
|
|
```
|
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
### Hint 2
|
2018-10-12 15:37:13 -04:00
|
|
|
Try using the '^' character caret outside of brackets as seen in the above example
|
|
|
|
|
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
|
|
|
|
---
|
|
|
|
## Solutions
|
|
|
|
|
|
|
|
<details><summary>Solution 1 (Click to Show/Hide)</summary>
|
|
|
|
|
2018-10-12 15:37:13 -04:00
|
|
|
```javascript
|
|
|
|
let rickyAndCal = "Cal and Ricky both like racing.";
|
|
|
|
let calRegex = /^Cal/; // Change this line
|
|
|
|
let result = calRegex.test(rickyAndCal);
|
|
|
|
```
|
2019-07-24 00:59:27 -07:00
|
|
|
|
|
|
|
</details>
|