-
Notifications
You must be signed in to change notification settings - Fork 0
/
25_specifyNumberOfMatches.js
39 lines (31 loc) · 1022 Bytes
/
25_specifyNumberOfMatches.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Specify Upper and Lower Number of Matches
/*
Quantity specifiers declared with curly brackets {}
allow matching to occur a required number of times.
The + is used to match one or more and * is for
matching zero or more times.
To match only the letter a from three to five times in
the string ah, the regex would be /a{3,5}h/.
*/
let a6 = "aaaaaah";
let a4 = "aaaah";
let a2 = "aah";
let multipleA = /a{3,5}h/;
let result = multipleA.test(a6);
console.log(result); // true
result = a6.match(multipleA);
console.log(result); // [ 'aaaaah' ]
result = multipleA.test(a4);
console.log(result); // true
result = a4.match(multipleA);
console.log(result); // [ 'aaaah' ]
result = multipleA.test(a2);
console.log(result); // false
result = a2.match(multipleA);
console.log(result); // null
/* Change the regex ohRegex to match the entire phrase
Oh no only when it has 3 to 6 letter h's */
let ohStr = "Ohhh no";
let ohRegex = /Oh{3,6} no/; // Change this line
result = ohRegex.test(ohStr);
console.log(result);