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 trialElizabeth McInerney
3,175 PointsTwitter, 3 tries
I have tried to get twitter 3 different ways. Each is failing. Please show me why.
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+.]+@[\w.]+),\s(?P<phone>\d{3}-\d{3}-\d{4})',string)
twitters = re.search(r'\s@[\w\d]+)',string)
twitters = re.search(r'^\s@[\w\d]+)$',string, re.M)
twitters = re.search(r'^(?P<twitter>\s@[\w\d]+)$',string, re.M)
1 Answer
kacperwikiel
15,795 Pointstwitters = re.search(r'(?P<twitter>)',string) #named group - catches nothing now twitters = re.search(r'(?P<twitter>@[\w])',string) #we will catch @ and word after that. twitters = re.search(r'(?P<twitter>@[\w]$)',string, re.MULTILINE) # $ - for end of line, and re.MULTILINE so each line will be parsed
Elizabeth McInerney
3,175 PointsElizabeth McInerney
3,175 PointsOk, this is what I do not get. Are you saying that you don't always use ^ and $ together? He used them together with re.M in the video. So if $ used together with re.M means look for something at the end of every line. What does ^$ used with re.M mean, or ^ used alone with re.M but without $?
Kenneth Love
Treehouse Guest TeacherKenneth Love
Treehouse Guest Teacher^
beginning of string/line$
end of string/lineYou can use them together or independently. They're just to indicate position in the string/line.
Elizabeth McInerney
3,175 PointsElizabeth McInerney
3,175 PointsThanks