/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); // Returns ["big"]
bagStr.match(bgRegex); // Returns ["bag"]
bugStr.match(bgRegex); // Returns ["bug"]
bogStr.match(bgRegex); // Returns null
a, e, i, o, u) in your regex vowelRegex to find all the vowels in the string quoteSample.
NotevowelRegex should use a character class.
testString: 'assert(/\[.*\]/.test(vowelRegex.source), "Your regex vowelRegex should use a character class.");'
- text: Your regex vowelRegex should use the global flag.
testString: 'assert(vowelRegex.flags.match(/g/).length == 1, "Your regex vowelRegex should use the global flag.");'
- text: Your regex vowelRegex should use the case insensitive flag.
testString: 'assert(vowelRegex.flags.match(/i/).length == 1, "Your regex vowelRegex should use the case insensitive flag.");'
- text: Your regex should not match any consonants.
testString: 'assert(!/[b-df-hj-np-tv-z]/gi.test(result.join()), "Your regex should not match any consonants.");'
```