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 trialRungano Matonda
3,237 PointsGreat! Now, make a new variable, twitters that is an re.search() where the pattern catches the Twitter handle for a pers
hey guys...need help here, I am getting twitters does not have a regex
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\d.]+)
,\s
(?P<phone>\d{3}-\d{3}-\d{4})
''', string, re.X|re.M)
print(contacts)
twitters = re.search(r'''
(?P<twitter>[@\w\d]+)
,\$
''',string,re.MULTILINE)
1 Answer
Dan Johnson
40,533 PointsSince you're escaping the $ it will try to match the character as is, rather than use it's special meaning for being the end of a string. The comma also won't match since the Twitter handle is the last thing on the line and the re.MULTILINE flag is being used.
The rest of your regex is fine, though you might need to add the re.VERBOSE flag with the use of the docstring.
Rungano Matonda
3,237 PointsRungano Matonda
3,237 PointsI have removed the escape hatchet on the $ and added the re.VERBOSE flag..It's now saying task1 no longer passing:(twitters = re.search(r''' (?P<twitter>[@\w\d]+) $ ''',string,re.VERBOSE,re.MULTILINE)
Dan Johnson
40,533 PointsDan Johnson
40,533 PointsTo combine flags you use the | operator. re.MULTILINE | re.VERBOSE for example. You'll end up with something like this:
Rungano Matonda
3,237 PointsRungano Matonda
3,237 PointsOh I had forgot about the "|" operator, I should go and revise on that...thanks a lot Mr Dan:)