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
chrisp
13,686 PointsFor the regular expression grouping construct, why is 'one' outputted and not 'zero'?
Not sure how the expression works and not getting the outputting process.
x = re.search('(?<=-)\w+', 'zero-one')
m.group(0)
'one'
1 Answer
karis hutcheson
7,036 PointsThis is because the expression
?<= # *something*
is a special "look-behind" character in Python regex. Meaning it's going to take whatever you put in something and look after it for the expression following.
(?<=-)\w+
looks for \w+ that occurs after a hyphen.
more information here: Python RegEx
chrisp
13,686 Pointschrisp
13,686 PointsThanks for the explanation, link, and examples. Now that looking through it again, it now makes sense, thanks you Karis. Just been 2 days I started with Python, so far it's pretty sweet!
All the best to you and your CS journey!
karis hutcheson
7,036 Pointskaris hutcheson
7,036 PointsNo prob! :) and thank you.