2.5 KiB
2.5 KiB
id, title, challengeType
id | title | challengeType |
---|---|---|
587d7db9367417b2b2512ba6 | Specify Only the Lower Number of Matches | 1 |
Description
quantity specifiers
using curly brackets. Sometimes you only want to specify the lower number of patterns with no upper limit.
To only specify the lower number of patterns, keep the first number followed by a comma.
For example, to match only the string "hah"
with the letter a
appearing at least 3
times, your regex would be /ha{3,}h/
.
let A4 = "haaaah";
let A2 = "haah";
let A100 = "h" + "a".repeat(100) + "h";
let multipleA = /ha{3,}h/;
multipleA.test(A4); // Returns true
multipleA.test(A2); // Returns false
multipleA.test(A100); // Returns true
Instructions
haRegex
to match the word "Hazzah"
only when it has four or more letter z
's.
Tests
- text: Your regex should use curly brackets.
testString: 'assert(haRegex.source.match(/{.*?}/).length > 0, "Your regex should use curly brackets.");'
- text: Your regex should not match <code>"Hazzah"</code>
testString: 'assert(!haRegex.test("Hazzah"), "Your regex should not match <code>"Hazzah"</code>");'
- text: Your regex should not match <code>"Hazzzah"</code>
testString: 'assert(!haRegex.test("Hazzzah"), "Your regex should not match <code>"Hazzzah"</code>");'
- text: Your regex should match <code>"Hazzzzah"</code>
testString: 'assert(haRegex.test("Hazzzzah"), "Your regex should match <code>"Hazzzzah"</code>");'
- text: Your regex should match <code>"Hazzzzzah"</code>
testString: 'assert(haRegex.test("Hazzzzzah"), "Your regex should match <code>"Hazzzzzah"</code>");'
- text: Your regex should match <code>"Hazzzzzzah"</code>
testString: 'assert(haRegex.test("Hazzzzzzah"), "Your regex should match <code>"Hazzzzzzah"</code>");'
- text: Your regex should match <code>"Hazzah"</code> with 30 <code>z</code>\'s in it.
testString: 'assert(haRegex.test("Ha" + "z".repeat(30) + "ah"), "Your regex should match <code>"Hazzah"</code> with 30 <code>z</code>\"s in it.");'
Challenge Seed
let haStr = "Hazzzzah";
let haRegex = /change/; // Change this line
let result = haRegex.test(haStr);
Solution
// solution required