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 Groups

Since \w includes \d, why are both included in the character class r'[-\w\d]' ?

In this case, wouldn't the specification \w\d be redundant? I have read that with RegEx you want to avoid placing tokens together where a given token's match could possibly be included in the previous token's match. I probably don't quite understand the concept. Can you clarify? Thank you

Y B
Y B
14,136 Points

I would love to know this aswell. After working through the course the impression i got was they were separate and was surprised when using a \w expression in the interpreter that it picked up numbers too.

1 Answer

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

I suppose, if you were really, really concerned about performance, you'd just use \w if you wanted both characters. You'd, of course, use \d if you only wanted numbers. Like most performance things, though, it's going to be an issue only for an extreme minority.