-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREGEX_Match_Single_Character_with_Multiple_Possibilities.js
More file actions
55 lines (43 loc) · 1.69 KB
/
REGEX_Match_Single_Character_with_Multiple_Possibilities.js
File metadata and controls
55 lines (43 loc) · 1.69 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
Match Single Character with Multiple Possibilities
You learned how to match
literal patterns (/literal/) and
wildcard character (/./).
Those are the extremes of regular expressions, where one
finds exact matches and the other matches everything.
There are options that are a balance between the two extremes.
You can search for a literal pattern with some flexibility
with character classes.
Character classes allow you to define a group of characters
you wish to match by placing them inside
square ([ and ]) brackets.
For example, you want to match bag, big, and bug but not bog.
You can create the regex /b[aiu]g/ to do this.
The [aiu] is the character class that will only match the
characters a, i, or u.
let bigStr = "big";
let bagStr = "bag";
let bugStr = "bug";
let bogStr = "bog";
let bgRegex = /b[aiu]g/;
bigStr.match(bgRegex);
bagStr.match(bgRegex);
bugStr.match(bgRegex);
bogStr.match(bgRegex);
In order, the four match calls would return the
values ["big"], ["bag"], ["bug"], and null.
EXERCISE
Use a character class with vowels (a, e, i, o, u) in your regex
vowelRegex to find all the vowels in the string quoteSample.
Note: Be sure to match both upper- and lowercase vowels.
You should find all 25 vowels.
Your regex vowelRegex should use a character class.
Your regex vowelRegex should use the global flag.
Your regex vowelRegex should use the case insensitive flag.
Your regex should not match any consonants.
*/
let quoteSample = "Beware of bugs in the above code; I have only proved it correct, not tried it.";
let vowelRegex = /[aeiou]/gi; // Change this line
//let result = vowelRegex.test(quoteSample); // Change this line
let result = quoteSample.match(vowelRegex);
console.log(result.length);