@@ -65,11 +65,11 @@ def test_matching_special_character(self):
6565 + "na2.xls\n " \
6666 + "sa1.xls"
6767 #TIP you can use the pattern .a. which matches in above test but in this case matches more than you want
68- self .assertEquals (len (re .findall (".a." , string )),3 , "I want to find all files for North America(na) or South America(sa)" )
68+ self .assertEquals (len (re .findall (__ , string )),3 , "I want to find all files for North America(na) or South America(sa)" )
6969
7070 def test_matching_set_character (self ):
7171 """
72- Lesson 1 Matching sets of characters
72+ Lesson 2 Matching sets of characters
7373
7474 A set of characters is defined using the metacharacters [ and ]. Everything between them is part of the set and
7575 any one of the set members must match (but not all).
@@ -84,5 +84,43 @@ def test_matching_set_character(self):
8484 + "sa1.xls\n " \
8585 + "ca1.xls"
8686 #TIP you can use the pattern .a. which matches in above test but in this case matches more than you want
87- self .assertEquals (len (re .findall (".a." , string )),3 , "I want to find all files for North America(na) or South America(sa), but not (ca)" )
87+ self .assertEquals (len (re .findall (__ , string )),3 , "I want to find all files for North America(na) or South America(sa), but not (ca)" )
88+
89+ def test_using_character_set_ranges (self ):
90+ """
91+ Lesson 2 Using character set ranges
92+
93+ The previous pattern could be [ns]a.\.xls and if a in the list had a file name sam.xls would be matched because the . matches all
94+ characters, not just digits. This can be solved with Character sets.
95+ You can use this pattern [ns]a[0123456789]\.xls but to simplify you can use a special metacharacter: - (hyphen). i.e [0-9]
96+
97+ - is only a metacharacter when used between [].
98+
99+ """
100+ string = "sales.xlx\n " \
101+ + "sales1.xls\n " \
102+ + "orders3.xls\n " \
103+ + "apac1.xls\n " \
104+ + "sales2.xls\n " \
105+ + "na1.xls\n " \
106+ + "na2.xls\n " \
107+ + "sa1.xls\n " \
108+ + "sam.xls\n " \
109+ + "ca1.xls"
110+ self .assertEquals (len (re .findall (__ , string )),3 , "I want to find all files for North America(na) or South America(sa), but not (ca)" )
111+
112+ def test_using_multiple_ranges (self ):
113+ """
114+ Lesson 2 Using character set ranges
115+
116+ The following are valid ranges:
117+ A-Z matches all uppercase characters from A to Z
118+ a-z matches all uppercase characters from a to z
119+ A-F matches all uppercase characters from A to F
120+ A-z matches all uppercase characters from A to z. This pattern also includes characters such as [ and ^
121+ Any two ASCII characters may be specified as the range start and end.
122+
123+ """
124+ string = '<BODY BGCOLOR="#336633" TEXT="#FFFFFF" MARGINWIDTH="0" MARGINHEIGHT="0" TOPMARGIN="0" LEFTMARGIN="0">'
125+ self .assertEquals (len (re .findall (__ , string )),2 , "I want to find all the colors in RGB" )
88126
0 commit comments