2018-10-04 14:37:37 +01:00
---
id: 587d7db4367417b2b2512b90
title: Match a Literal String with Different Possibilities
challengeType: 1
2019-08-05 09:17:33 -07:00
forumTopicId: 301345
2021-01-13 03:31:00 +01:00
dashedName: match-a-literal-string-with-different-possibilities
2018-10-04 14:37:37 +01:00
---
2020-11-27 19:02:05 +01:00
# --description--
2018-10-04 14:37:37 +01:00
2020-11-27 19:02:05 +01:00
Using regexes like `/coding/` , you can look for the pattern `"coding"` in another string.
This is powerful to search single strings, but it's limited to only one pattern. You can search for multiple patterns using the `alternation` or `OR` operator: `|` .
This operator matches patterns either before or after it. For example, if you wanted to match `"yes"` or `"no"` , the regex you want is `/yes|no/` .
You can also search for more than just two patterns. You can do this by adding more patterns with more `OR` operators separating them, like `/yes|no|maybe/` .
# --instructions--
Complete the regex `petRegex` to match the pets `"dog"` , `"cat"` , `"bird"` , or `"fish"` .
# --hints--
Your regex `petRegex` should return `true` for the string `"John has a pet dog."`
```js
assert(petRegex.test('John has a pet dog.'));
2018-10-04 14:37:37 +01:00
```
2020-11-27 19:02:05 +01:00
Your regex `petRegex` should return `false` for the string `"Emma has a pet rock."`
2018-10-04 14:37:37 +01:00
2020-11-27 19:02:05 +01:00
```js
assert(!petRegex.test('Emma has a pet rock.'));
```
2018-10-04 14:37:37 +01:00
2020-11-27 19:02:05 +01:00
Your regex `petRegex` should return `true` for the string `"Emma has a pet bird."`
2018-10-04 14:37:37 +01:00
```js
2020-11-27 19:02:05 +01:00
assert(petRegex.test('Emma has a pet bird.'));
2018-10-04 14:37:37 +01:00
```
2020-11-27 19:02:05 +01:00
Your regex `petRegex` should return `true` for the string `"Liz has a pet cat."`
2018-10-04 14:37:37 +01:00
2020-11-27 19:02:05 +01:00
```js
assert(petRegex.test('Liz has a pet cat.'));
```
2018-10-04 14:37:37 +01:00
2020-11-27 19:02:05 +01:00
Your regex `petRegex` should return `false` for the string `"Kara has a pet dolphin."`
2018-10-04 14:37:37 +01:00
2020-11-27 19:02:05 +01:00
```js
assert(!petRegex.test('Kara has a pet dolphin.'));
```
2018-10-04 14:37:37 +01:00
2020-11-27 19:02:05 +01:00
Your regex `petRegex` should return `true` for the string `"Alice has a pet fish."`
```js
assert(petRegex.test('Alice has a pet fish.'));
```
Your regex `petRegex` should return `false` for the string `"Jimmy has a pet computer."`
```js
assert(!petRegex.test('Jimmy has a pet computer.'));
```
# --seed--
## --seed-contents--
2018-10-04 14:37:37 +01:00
```js
2019-05-03 03:05:26 -07:00
let petString = "James has a pet cat.";
2020-11-27 19:02:05 +01:00
let petRegex = /change/; // Change this line
2019-05-03 03:05:26 -07:00
let result = petRegex.test(petString);
2018-10-04 14:37:37 +01:00
```
2019-07-18 08:24:12 -07:00
2020-11-27 19:02:05 +01:00
# --solutions--
```js
let petString = "James has a pet cat.";
let petRegex = /dog|cat|bird|fish/; // Change this line
let result = petRegex.test(petString);
```