--description--
Recall that you use the plus sign +
to look for one or more characters and the asterisk *
to look for zero or more characters. These are convenient but sometimes you want to match a certain range of patterns.
You can specify the lower and upper number of patterns with quantity specifiers. Quantity specifiers are used with curly brackets ({
and }
). You put two numbers between the curly brackets - for the lower and upper number of patterns.
For example, to match only the letter a
appearing between 3
and 5
times in the string ah
, your regex would be /a{3,5}h/
.
let A4 = "aaaah";
let A2 = "aah";
let multipleA = /a{3,5}h/;
multipleA.test(A4);
multipleA.test(A2);
The first test
call would return true
, while the second would return false
.
--instructions--
Change the regex ohRegex
to match the entire phrase Oh no
only when it has 3
to 6
letter h
's.
--hints--
Your regex should use curly brackets.
assert(ohRegex.source.match(/{.*?}/).length > 0);
Your regex should not match the string Ohh no
ohRegex.lastIndex = 0;
assert(!ohRegex.test('Ohh no'));
Your regex should match the string Ohhh no
assert('Ohhh no'.match(ohRegex)[0].length === 7);
Your regex should match the string Ohhhh no
assert('Ohhhh no'.match(ohRegex)[0].length === 8);
Your regex should match the string Ohhhhh no
assert('Ohhhhh no'.match(ohRegex)[0].length === 9);
Your regex should match the string Ohhhhhh no
assert('Ohhhhhh no'.match(ohRegex)[0].length === 10);
Your regex should not match the string Ohhhhhhh no
ohRegex.lastIndex = 0;
assert(!ohRegex.test('Ohhhhhhh no'));
--seed--
--seed-contents--
let ohStr = "Ohhh no";
let ohRegex = /change/; // Change this line
let result = ohRegex.test(ohStr);
--solutions--
let ohStr = "Ohhh no";
let ohRegex = /Oh{3,6} no/; // Change this line
let result = ohRegex.test(ohStr);