Skip to content

Commit b22f202

Browse files
committed
added two cases
1 parent 45e72b2 commit b22f202

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

python 2/koans/about_regex.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,37 @@ def test_matching_literal_text_how_many(self):
3535
self.assertEqual(len(m),2, "I want to know how many times appears my name")
3636

3737

38+
def test_matching_any_character(self):
39+
"""
40+
Lesson 1 Matching any character
41+
42+
. matches any character, alphabetic characters, digits and .
43+
"""
44+
string = "pecks.xlx\n" \
45+
+ "orders1.xls\n" \
46+
+ "apec1.xls\n" \
47+
+ "na1.xls\n" \
48+
+ "na2.xls\n" \
49+
+ "sa1.xls"
50+
51+
#TIP: remember the issue of this lesson
52+
self.assertEquals(len(re.findall("a", string)),3, "I want to find all files for North America(na) or South America(sa)")
53+
3854

55+
def test_matching_special_character(self):
56+
"""
57+
Lesson 1 Matching special character
58+
59+
Uses \ if you want to match special character
60+
"""
61+
string = "sales.xlx\n" \
62+
+ "sales1.xls\n" \
63+
+ "orders1.xls\n" \
64+
+ "apac1.xls\n" \
65+
+ "sales2.xls\n" \
66+
+ "na1.xls\n" \
67+
+ "na2.xls\n" \
68+
+ "sa1.xls"
69+
#TIP you can use the pattern .a. which matches in above test but in this case matches more than you want
70+
self.assertEquals(len(re.findall(".a.", string)),3, "I want to find all files for North America(na) or South America(sa)")
71+

0 commit comments

Comments
 (0)