Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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,484 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)