forked from liammclennan/JavaScript-Koans
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathabout_regular_expressions.js
More file actions
31 lines (24 loc) · 1.09 KB
/
about_regular_expressions.js
File metadata and controls
31 lines (24 loc) · 1.09 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
module("About Regular Expressions (topics/about_regular_expressions.js)");
// test("exec", function() {
// var numberFinder = /(\d).*(\d)/;
// var results = numberFinder.exec("what if 6 turned out to be 9?");
// ok(results.equalTo([__, __, __]), 'what is the value of results?');
// });
test("test", function() {
var containsSelect = /select/.test(" select * from users ");
equal(true, containsSelect, 'does the string provided contain "select"?');
});
// test("match", function() {
// var matches = "what if 6 turned out to be 9?".match(/(\d)/g);
// ok(matches.equalTo([6, 9]), 'what is the value of matches?');
// });
test("replace", function() {
var pie = "apple pie".replace("apple", "strawberry");
equal("strawberry pie", pie, 'what is the value of pie?');
pie = "what if 6 turned out to be 9?".replace(/\d/g, function(number) { // the second parameter can be a string or a function
var map = {'6': 'six','9': 'nine'};
return map[number];
});
equal("what if six turned out to be nine?", pie, 'what is the value of pie?');
});
// THE END