Created
September 11, 2021 23:28
-
-
Save yitonghe00/1b670d159afdd60c6dfd89420f2d84c6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Fill in the regular expressions | |
verify(/ca[rt]/, | |
["my car", "bad cats"], | |
["camper", "high art"]); | |
verify(/pr?op/, | |
["pop culture", "mad props"], | |
["plop", "prrrop"]); | |
verify(/ferr(et|y|ari)/, | |
["ferret", "ferry", "ferrari"], | |
["ferrum", "transfer A"]); | |
verify(/ious\b/, | |
["how delicious", "spacious room"], | |
["ruinous", "consciousness"]); | |
verify(/\s[,.;:]/, | |
["bad punctuation ."], | |
["escape the period"]); | |
verify(/\w{7}/, | |
["Siebentausenddreihundertzweiundzwanzig"], | |
["no", "three small words"]); | |
verify(/\b[^\We]+\b/i, | |
["red platypus", "wobbling nest"], | |
["earth bed", "learning ape", "BEET"]); | |
function verify(regexp, yes, no) { | |
// Ignore unfinished exercises | |
if (regexp.source == "...") return; | |
for (let str of yes) if (!regexp.test(str)) { | |
console.log(`Failure to match '${str}'`); | |
} | |
for (let str of no) if (regexp.test(str)) { | |
console.log(`Unexpected match for '${str}'`); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment