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 trialMona Jalal
4,302 Pointsconfusion about \b
so when to use each?
print(re.findall(r'\b[trehous]{9}\b', names, re.I))
print(re.findall(r'[trehous]{9}', names, re.I))
1 Answer
Chris Freeman
Treehouse Moderator 68,441 PointsThe regex character \b
represents a zero-length position at a word boundary. It is used if you are looking for whole words and reject matches that may be inside other words.
In your example, ypu would you'd the \b
to say "I am looking for a sequence of 9 characters from this set but not sequences that are within sequences of 10 or more characters.
This means using \b
would reject matching "treehouses" since 9 characters aren't surrounded by word boundaries.