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
Zach Hudson
7,702 PointsError Message: Don't get a regex search object
I keep getting the "Don't get a regex search object" error message. I have tried tweaking the below code a few different ways and still get the error. Any input would be appreciated...
import re
string = '''Love, Kenneth, kenneth+challenge@teamtreehouse.com, 555-555-5555, @kennethlove
Chalkley, Andrew, andrew@teamtreehouse.co.uk, 555-555-5556, @chalkers
McFarland, Dave, dave.mcfarland@teamtreehouse.com, 555-555-5557, @davemcfarland
Kesten, Joy, joy@teamtreehouse.com, 555-555-5558, @joykesten'''
contacts = re.search(r'''
(?P<email>[\w\d\W]+@[\w\W]+),
(?P<phone>[\d{3}]-[\d{3}]-[\d{4}])
''', string, re.X|re.M)
2 Answers
john larson
16,594 Points# email # [added - got rid of \W, added . and +]+@[added -\d.]
# ,\s looks like you just missed a space
# phone # got rid of []
contacts = re.search(r"""
(?P<email>[-\w\d.+]+@[-\w\d.]+)
,\s
(?P<phone>\d{3}-\d{3}-\d{4}) # got rid of []
""", string, re.X|re.M)
Zach Hudson
7,702 PointsJohn, won't '\W 'include the dash (-), dot (.), and plus (+)? How is this different?
Thanks for your input by the way.
john larson
16,594 PointsSomeone else will probably get to it before me, but when you have trouble with a challenge..if you use the help button FOR that challenge...it will put a link for others to view the challenge. For me, I like to go through the challenge from beginning to end. It's cathartic and reinforces my learning (and things I forgot)
Brian Jensen
Treehouse StaffThis is the challenge he is working on: View Challenge
(and I 100% agree)
john larson
16,594 Pointsjohn larson
16,594 PointsMaybe it would, but it looked like it would cancel out \w. I'm not claiming to have a clear thought process on this. I remember doing the same thing as you on the phone with the brackets. It just seemed like the thing to do. But it doesn't work that way. regular expressions was kinda hard for me. I first ran into it in w3Schools as part of JavaScript. I remember thinking "I hope i never need this".