Skip to content

Commit 36da328

Browse files
committed
added one case with negate ranges
1 parent 4418902 commit 36da328

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

python 2/koans/about_regex.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,26 @@ def test_using_multiple_ranges(self):
124124
string = '<BODY BGCOLOR="#336633" TEXT="#FFFFFF" MARGINWIDTH="0" MARGINHEIGHT="0" TOPMARGIN="0" LEFTMARGIN="0">'
125125
self.assertEquals(len(re.findall(__, string)),2, "I want to find all the colors in RGB")
126126

127+
128+
def test_anything_but_matching(self):
129+
"""
130+
Lesson 2 Using character set ranges
131+
Occsionally, you'll want a list of characters that you don't want to match.
132+
Character sets can be negated using the ^ metacharacter.
133+
134+
"""
135+
string = "sales.xlx\n" \
136+
+ "sales1.xls\n" \
137+
+ "orders3.xls\n" \
138+
+ "apac1.xls\n" \
139+
+ "sales2.xls\n" \
140+
+ "sales3.xls\n" \
141+
+ "europe2.xls\n" \
142+
+ "sam.xls\n" \
143+
+ "na1.xls\n" \
144+
+ "na2.xls\n" \
145+
+ "sa1.xls\n" \
146+
+ "ca1.xls"
147+
m = re.search("[ns]a[^0-9]\.xls", string)
148+
self.assertTrue(m and m.group(0) and m.group(0)== 'sam.xls', "I want to find the name sam")
149+

0 commit comments

Comments
 (0)