2018-10-10 18:03:03 -04:00
---
id: 587d7db5367417b2b2512b94
2021-02-06 04:42:36 +00:00
title: Match Anything with Wildcard Period
2018-10-10 18:03:03 -04:00
challengeType: 1
2020-08-04 15:14:01 +08:00
forumTopicId: 301348
2021-01-13 03:31:00 +01:00
dashedName: match-anything-with-wildcard-period
2018-10-10 18:03:03 -04:00
---
2020-12-16 00:37:30 -07:00
# --description--
2021-02-06 04:42:36 +00:00
Sometimes you won't (or don't need to) know the exact characters in your patterns. Thinking of all words that match, say, a misspelling would take a long time. Luckily, you can save time using the wildcard character: `.`
2020-12-16 00:37:30 -07:00
2021-02-06 04:42:36 +00:00
The wildcard character `.` will match any one character. The wildcard is also called `dot` and `period` . You can use the wildcard character just like any other character in the regex. For example, if you wanted to match `"hug"` , `"huh"` , `"hut"` , and `"hum"` , you can use the regex `/hu./` to match all four words.
2020-08-04 15:14:01 +08:00
```js
let humStr = "I'll hum a song";
let hugStr = "Bear hug";
let huRegex = /hu./;
huRegex.test(humStr); // Returns true
huRegex.test(hugStr); // Returns true
```
2020-12-16 00:37:30 -07:00
# --instructions--
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
Complete the regex `unRegex` so that it matches the strings `"run"` , `"sun"` , `"fun"` , `"pun"` , `"nun"` , and `"bun"` . Your regex should use the wildcard character.
2020-12-16 00:37:30 -07:00
# --hints--
2021-02-06 04:42:36 +00:00
You should use the `.test()` method.
2020-12-16 00:37:30 -07:00
```js
assert(code.match(/\.test\(.*\)/));
2018-10-10 18:03:03 -04:00
```
2021-02-06 04:42:36 +00:00
You should use the wildcard character in your regex `unRegex`
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
```js
assert(/\./.test(unRegex.source));
```
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
Your regex `unRegex` should match `"run"` in `"Let us go on a run."`
2018-10-10 18:03:03 -04:00
```js
2021-02-06 04:42:36 +00:00
unRegex.lastIndex = 0;
2020-12-16 00:37:30 -07:00
assert(unRegex.test('Let us go on a run.'));
2018-10-10 18:03:03 -04:00
```
2021-02-06 04:42:36 +00:00
Your regex `unRegex` should match `"sun"` in `"The sun is out today."`
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
```js
2021-02-06 04:42:36 +00:00
unRegex.lastIndex = 0;
2020-12-16 00:37:30 -07:00
assert(unRegex.test('The sun is out today.'));
```
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
Your regex `unRegex` should match `"fun"` in `"Coding is a lot of fun."`
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
```js
2021-02-06 04:42:36 +00:00
unRegex.lastIndex = 0;
2020-12-16 00:37:30 -07:00
assert(unRegex.test('Coding is a lot of fun.'));
```
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
Your regex `unRegex` should match `"pun"` in `"Seven days without a pun makes one weak."`
2018-10-10 18:03:03 -04:00
```js
2021-02-06 04:42:36 +00:00
unRegex.lastIndex = 0;
2020-12-16 00:37:30 -07:00
assert(unRegex.test('Seven days without a pun makes one weak.'));
2018-10-10 18:03:03 -04:00
```
2020-08-04 15:14:01 +08:00
2021-02-06 04:42:36 +00:00
Your regex `unRegex` should match `"nun"` in `"One takes a vow to be a nun."`
2020-12-16 00:37:30 -07:00
```js
2021-02-06 04:42:36 +00:00
unRegex.lastIndex = 0;
2020-12-16 00:37:30 -07:00
assert(unRegex.test('One takes a vow to be a nun.'));
```
2021-02-06 04:42:36 +00:00
Your regex `unRegex` should match `"bun"` in `"She got fired from the hot dog stand for putting her hair in a bun."`
2020-12-16 00:37:30 -07:00
```js
2021-02-06 04:42:36 +00:00
unRegex.lastIndex = 0;
2020-12-16 00:37:30 -07:00
assert(
unRegex.test(
'She got fired from the hot dog stand for putting her hair in a bun.'
)
);
```
2021-02-06 04:42:36 +00:00
Your regex `unRegex` should not match `"There is a bug in my code."`
2020-12-16 00:37:30 -07:00
```js
2021-02-06 04:42:36 +00:00
unRegex.lastIndex = 0;
2020-12-16 00:37:30 -07:00
assert(!unRegex.test('There is a bug in my code.'));
```
2021-02-06 04:42:36 +00:00
Your regex `unRegex` should not match `"Catch me if you can."`
2020-12-16 00:37:30 -07:00
```js
2021-02-06 04:42:36 +00:00
unRegex.lastIndex = 0;
assert(!unRegex.test('Catch me if you can.'));
2020-12-16 00:37:30 -07:00
```
2021-01-13 03:31:00 +01:00
# --seed--
## --seed-contents--
```js
let exampleStr = "Let's have fun with regular expressions!";
let unRegex = /change/; // Change this line
let result = unRegex.test(exampleStr);
```
2020-12-16 00:37:30 -07:00
# --solutions--
2021-01-13 03:31:00 +01:00
```js
let exampleStr = "Let's have fun with regular expressions!";
let unRegex = /.un/; // Change this line
let result = unRegex.test(exampleStr);
```