On the Reuse Patterns Using Capture Groups, there's a missing test case that allows solutions that do not match the requirements.
The requirements read (emphasis added):
Use capture groups in reRegex to match a string that consists of only the same number repeated exactly three times separated by single spaces.
However, there's no test to confirm that a regex only matches single whitespace characters. Consider the following solution:
let reRegex = /^(\d+)\s+\1\s+\1$/;
This will match "42 42 42" and "42\t42\t42", neither of which meet the requirements of having a single space character delimiting the numbers.
I propose adding two additional test cases to prevent overly-permissive solutions:
Your regex should not match the string `42\t42\t42`.
```js
reRegex.lastIndex = 0;
assert(!reRegex.test('42\t42\t42'));
```
Your regex should not match the string `42 42 42`.
```js
reRegex.lastIndex = 0;
assert(!reRegex.test('42 42 42'));
```
See:
|
# --hints-- |
|
|
|
Your regex should use the shorthand character class for digits. |
|
|
|
```js |
|
assert(reRegex.source.match(/\\d/)); |
|
``` |
|
|
|
Your regex should reuse a capture group twice. |
|
|
|
```js |
|
assert(reRegex.source.match(/\\1|\\2/g).length >= 2); |
|
``` |
|
|
|
Your regex should match the string `42 42 42`. |
|
|
|
```js |
|
reRegex.lastIndex = 0; |
|
assert(reRegex.test('42 42 42')); |
|
``` |
|
|
|
Your regex should match the string `100 100 100`. |
|
|
|
```js |
|
reRegex.lastIndex = 0; |
|
assert(reRegex.test('100 100 100')); |
|
``` |
|
|
|
Your regex should not match the string `42 42 42 42`. |
|
|
|
```js |
|
assert.equal('42 42 42 42'.match(reRegex.source), null); |
|
``` |
|
|
|
Your regex should not match the string `42 42`. |
|
|
|
```js |
|
assert.equal('42 42'.match(reRegex.source), null); |
|
``` |
|
|
|
Your regex should not match the string `101 102 103`. |
|
|
|
```js |
|
reRegex.lastIndex = 0; |
|
assert(!reRegex.test('101 102 103')); |
|
``` |
|
|
|
Your regex should not match the string `1 2 3`. |
|
|
|
```js |
|
reRegex.lastIndex = 0; |
|
assert(!reRegex.test('1 2 3')); |
|
``` |
|
|
|
Your regex should match the string `10 10 10`. |
|
|
|
```js |
|
reRegex.lastIndex = 0; |
|
assert(reRegex.test('10 10 10')); |
|
``` |
|
|
On the Reuse Patterns Using Capture Groups, there's a missing test case that allows solutions that do not match the requirements.
The requirements read (emphasis added):
However, there's no test to confirm that a regex only matches single whitespace characters. Consider the following solution:
This will match
"42 42 42"and"42\t42\t42", neither of which meet the requirements of having a single space character delimiting the numbers.I propose adding two additional test cases to prevent overly-permissive solutions:
See:
freeCodeCamp/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/reuse-patterns-using-capture-groups.md
Lines 38 to 98 in b35e816