* feat(tools): add seed/solution restore script * chore(curriculum): remove empty sections' markers * chore(curriculum): add seed + solution to Chinese * chore: remove old formatter * fix: update getChallenges parse translated challenges separately, without reference to the source * chore(curriculum): add dashedName to English * chore(curriculum): add dashedName to Chinese * refactor: remove unused challenge property 'name' * fix: relax dashedName requirement * fix: stray tag Remove stray `pre` tag from challenge file. Signed-off-by: nhcarrigan <nhcarrigan@gmail.com> Co-authored-by: nhcarrigan <nhcarrigan@gmail.com>
2.4 KiB
id, title, challengeType, forumTopicId, dashedName
id | title | challengeType | forumTopicId | dashedName |
---|---|---|---|---|
587d7db5367417b2b2512b95 | Match Single Character with Multiple Possibilities | 1 | 301357 | match-single-character-with-multiple-possibilities |
--description--
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); // Returns ["big"]
bagStr.match(bgRegex); // Returns ["bag"]
bugStr.match(bgRegex); // Returns ["bug"]
bogStr.match(bgRegex); // Returns null
--instructions--
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.
--hints--
You should find all 25 vowels.
assert(result.length == 25);
Your regex vowelRegex
should use a character class.
assert(/\[.*\]/.test(vowelRegex.source));
Your regex vowelRegex
should use the global flag.
assert(vowelRegex.flags.match(/g/).length == 1);
Your regex vowelRegex
should use the case insensitive flag.
assert(vowelRegex.flags.match(/i/).length == 1);
Your regex should not match any consonants.
assert(!/[b-df-hj-np-tv-z]/gi.test(result.join()));
--seed--
--seed-contents--
let quoteSample = "Beware of bugs in the above code; I have only proved it correct, not tried it.";
let vowelRegex = /change/; // Change this line
let result = vowelRegex; // Change this line
--solutions--
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 = quoteSample.match(vowelRegex); // Change this line