Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Regular Expressions in Python Introduction to Regular Expressions Groups

Oti Oritsejafor
Oti Oritsejafor
3,281 Points

I get back nothing

It just gives me back "[]". Help please?

print(re.findall(r'''
^([-\w ]*,\s[-w\ ]+)\t   # Last names and first names.
([-\w\d+.]+@[-\w\d.]+)\t    # Email
(\(?\d{3}\)?-?\s?\d{3}-\d{4})?\t     # Phone
([\w\s]+,\s[\w\s.]+)\t?       # Job and company
(@[\w\d]+)?$             # Twitter
''', data, re.X|re.M))

2 Answers

Oti Oritsejafor
Oti Oritsejafor
3,281 Points

It seems that you made a mistake on your second line:

^([-\w ]*,\s[-w\ ]+)\t   # Last names and first names. # Change "-w\" to "-\w" and that should fix it.
Oti Oritsejafor
Oti Oritsejafor
3,281 Points

Sorry, I meant "it seems I(not you) made a mistake on the second line".

Cindy Lea
PLUS
Cindy Lea
Courses Plus Student 6,497 Points

Do you have a string somewhere that contains any values for checking against? I think you're missing some code. For example from code.runnable.com I found this:

import re

string = "Once you have accomplished small things, you may attempt great ones safely."

# Return all words beginning with character 'a', as a list of strings
print re.findall(r"\ba[\w]*", string)
# ['accomplished', 'attempt']

# Return all words beginning with character 'a', as an iterator yielding match objects
it = re.finditer(r"\ba[\w]*", string)
for match in it:
    print "'{g}' was found between the indices {s}".format(g=match.group(), s=match.span())
# 'accomplished' was found between the indices (14, 26)
# 'attempt' was found between the indices (49, 56)