2.6 KiB
2.6 KiB
id, title, challengeType
id | title | challengeType |
---|---|---|
587d7db9367417b2b2512ba5 | Specify Upper and Lower Number of Matches | 1 |
Description
+
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); // Returns true
multipleA.test(A2); // Returns false
Instructions
ohRegex
to match only 3
to 6
letter h
's in the word "Oh no"
.
Tests
- text: Your regex should use curly brackets.
testString: 'assert(ohRegex.source.match(/{.*?}/).length > 0, "Your regex should use curly brackets.");'
- text: Your regex should not match <code>"Ohh no"</code>
testString: 'assert(!ohRegex.test("Ohh no"), "Your regex should not match <code>"Ohh no"</code>");'
- text: Your regex should match <code>"Ohhh no"</code>
testString: 'assert(ohRegex.test("Ohhh no"), "Your regex should match <code>"Ohhh no"</code>");'
- text: Your regex should match <code>"Ohhhh no"</code>
testString: 'assert(ohRegex.test("Ohhhh no"), "Your regex should match <code>"Ohhhh no"</code>");'
- text: Your regex should match <code>"Ohhhhh no"</code>
testString: 'assert(ohRegex.test("Ohhhhh no"), "Your regex should match <code>"Ohhhhh no"</code>");'
- text: Your regex should match <code>"Ohhhhhh no"</code>
testString: 'assert(ohRegex.test("Ohhhhhh no"), "Your regex should match <code>"Ohhhhhh no"</code>");'
- text: Your regex should not match <code>"Ohhhhhhh no"</code>
testString: 'assert(!ohRegex.test("Ohhhhhhh no"), "Your regex should not match <code>"Ohhhhhhh no"</code>");'
Challenge Seed
let ohStr = "Ohhh no";
let ohRegex = /change/; // Change this line
let result = ohRegex.test(ohStr);
Solution
// solution required