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

Python Regular Expressions in Python Introduction to Regular Expressions Word Length

Not sure what to put as the search pattern, nothing I'm trying seems to be working.

I'm sure its obvious but I'm stumped. Looking at solutions on stackoverflow involving [a-zA-Z] is just confusing me more.

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

The challenge asks "return a list of the words in the string that are 'count' word characters long or longer". In a regular expression search a word character is represented with \w. To find count many characters, you can multiply this short string by count. Then to also find words of greater length, you can search for \w* which means "zero or more word characters". putting these together you get:

import re

​def find_words(count, string):
    return re.findall(r'\w' * count + '\w*', string)

Thank you. :)

Ivan Bodnar
Ivan Bodnar
2,419 Points

Thanks Chris, I was stuck too, I was trying to do it with .format()