@@ -144,6 +144,42 @@ def test_anything_but_matching(self):
144144 + "na2.xls\n " \
145145 + "sa1.xls\n " \
146146 + "ca1.xls"
147- m = re .search ("[ns]a[^0-9]\.xls" , string )
147+ m = re .search (__ , string )
148148 self .assertTrue (m and m .group (0 ) and m .group (0 )== 'sam.xls' , "I want to find the name sam" )
149149
150+ def using_metacharacters_escaping (self ):
151+ """
152+ Lesson 3 Using metacharacters
153+
154+ Metacharacters are characters that have special meaning within regular expressions.
155+
156+ Metacharacters can be escaped by preceding them with a backslash, therefore \. matches .
157+ """
158+ string = "var myArray = new Array();\n " \
159+ + "if (myArray[0]) { \n " \
160+ + "}"
161+ m = re .search ("myArray[0]" , string ) #TIP: This pattern matches "myArray0" because [ and ] are metacharacters
162+ self .assertTrue (m and m .group (0 ) and m .group (0 )== 'myArray[0]' , "I want to find myArray[0]" )
163+
164+ def using_metacharacters_matching_white_spaces (self ):
165+ """
166+ Lesson 3 Matching whitespace character
167+
168+ Sometimes you'll have to match nonprinting whitespace characters embedded in your text. For example tab characters
169+ or line breaks .
170+ In this cases you can use these special metacharacters:
171+ [\b ] Backspace
172+ \f Form feed
173+ \n Line feed
174+ \r Carriage return
175+ \t Tab
176+ \v Vertical tab
177+
178+ """
179+ f = open ('koans/regex_cvs' , 'r' )
180+ string = f .read ()
181+ #This text contains a series of records in comma-delimited format (cvs). Before processing the records, you need
182+ # to remove any blank lines in the data.
183+ m = re .search ("" , string )
184+ self .assertTrue (m and m .group (0 ) and m .group (0 )== '\n \n ' , "I want to find the blank lines" )
185+
0 commit comments