Link
Lesson 1: An Introduction, and the ABCs
| Task | Text |
|---|
| Match | abcdefg |
| Match | abcde |
| Match | abc |
re.match('abc', text)
Lesson 1½: The 123s
| Task | Text |
|---|
| Match | abc123xyz |
| Match | define "123" |
| Match | var g = 123; |
re.match('.*123', text)
re.match('.*\d', text)
Lesson 2: The Dot
| Task | Text |
|---|
| Match | abc123xyz |
| Match | define "123" |
| Match | var g = 123; |
re.match('.+\.', text)
Lesson 3: Matching specific characters
| Task | Text |
|---|
| Match | can |
| Match | man |
| Match | fan |
| Skip | dan |
| Skip | ran |
| Skip | pan |
re.match('[cmf]an', text)
Lesson 4: Excluding specific characters
| Task | Text |
|---|
| Match | hog |
| Match | dog |
| Skip | bog |
re.match('[^b]og', text)
Lesson 5: Character ranges
| Task | Text |
|---|
| Match | Ana |
| Match | Bob |
| Match | Cpc |
| Skip | aax |
| Skip | bby |
| Skip | ccz |
re.match('[A-Z]',text)
Lesson 6: Catching some zzz's
| Task | Text |
|---|
| Match | wazzzzzup |
| Match | wazzzup |
| Skip | wazup |
- answer :
z{2}
- solution :
waz{3,5}up
re.match('.+z{2}',text)
Lesson 7: Mr. Kleene, Mr. Kleene
| Task | Text |
|---|
| Match | aaaabcc |
| Match | aabbbbc |
| Match | aacc |
| Skip | a |
- answer :
a{2,4}.\D*c$
- solution :
aa+b*c+
or a{2,4}b{0,4}c{1,2}
re.match('a{2,4}.\D*c$',text)
Lesson 8: Characters optional
| Task | Text |
|---|
| Match | 1 file found? |
| Match | 2 files found? |
| Match | 24 files found? |
| Skip | No files found. |
- answer :
\d
or \? or \d.*\?$
- solution :
\d+ files? found\?
re.match('\d.*\?$',text)
Lesson 9: All this whitespace
| Task | Text |
|---|
| Match | 1. abc |
| Match | 2. abc |
| Match | 3. abc |
| Skip | 4.abc |
- answer :
\d.\s or \d*\s
- solution :
\d\.\s+abc
re.match('\d\.\s+abc',text)
Lesson 10: Starting and ending
| Task | Text |
|---|
| Match | Mission: successful |
| Skip | Last Mission: unsuccessful |
| Skip | Next Mission: successful upon capture of target |
- answer :
^Mission.*\D
- solution :
^Mission: successful$
re.match('^Mission.*\D',text)
Lesson 11: Match groups
| Task | Text | Capture Groups |
|---|
| Capture | file_record_transcript.pdf | file_record_transcript |
| Capture | file_07241999.pdf | file_07241999 |
| Skip | testfile_fake.pdf.tmp | |
- solution :
^(file.+)\.pdf$
re.match('^(file.+)\.pdf$',text)
Lesson 12: Nested groups
| Task | Text | Capture Groups |
|---|
| Capture | Jan 1987 | (Jan 1987) (1987) |
| Capture | May 1969 | (May 1969) (1969) |
| Capture | Aug 2011 | (Aug 2011) (2011) |
- answer :
((\D+)(\d{4}))
- solution :
(\w+ (\d+))
re.match('((\D+)(\d{4}))',text)
re.match('(\w+ (\d+))',text)
Lesson 13: More group work
| Task | Text | Capture Groups |
|---|
| Capture | 1280x720 | 1280 720 |
| Capture | 1920x1600 | 1920 1600 |
| Capture | 1024x768 | 1024 768 |
- answer :
(\d{4})x(\d{3,4})
- solution :
(\d+)x(\d+)
re.match('(\d{4})x(\d{3,4})',text)
re.match('(\d+)x(\d+)',text)
Lesson 14: It's all conditional
| Task | Text |
|---|
| Match | I love cats |
| Match | I love dogs |
| Skip | I love logs |
| Skip | I love cogs |
- answer :
I love +(cats|dogs)
re.match('I love +(cats|dogs)',text)
Lesson 15: Other special characters
Other special characters