-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathregexp_golf_completejavascript.com.js
More file actions
43 lines (34 loc) · 1012 Bytes
/
regexp_golf_completejavascript.com.js
File metadata and controls
43 lines (34 loc) · 1012 Bytes
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
// Fill in the regular expressions
verify(/ca(r|t)/,
["my car", "bad cats"],
["camper", "high art"]);
verify(/pr?op/,
["pop culture", "mad props"],
["plop"]);
verify(/ferr(e|y|a)(\w*)/,
["ferret", "ferry", "ferrari"],
["ferrum", "transfer A"]);
verify(/(\w+)?ious\b/,
["how delicious", "spacious room"],
["ruinous", "consciousness"]);
verify(/\s[.,:;]/,
["bad punctuation ."],
["escape the dot"]);
verify(/(\w){7,}/,
["hottentottententen"],
["no", "hotten totten tenten"]);
verify(/^(\w+ [^e]+|[^e]+ \w+)$/,
["red platypus", "wobbling nest"],
["earth bed", "learning ape"]);
function verify(regexp, yes, no) {
// Ignore unfinished exercises
if (regexp.source == "...") return;
yes.forEach(function(s) {
if (!regexp.test(s))
console.log("Failure to match '" + s + "'");
});
no.forEach(function(s) {
if (regexp.test(s))
console.log("Unexpected match for '" + s + "'");
});
}