Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Regular Expressions in Python Introduction to Regular Expressions Negated Numbers

Jason Smith
Jason Smith
6,946 Points

Bummer: `good_numbers` seems to be missing or empty.

im not sure where i messed up, can you point me in the right direction?

negate.py
import re

string = '1234567890'

good_numbers = re.findall(r'[0-4][^5-7][8-9]', string)

3 Answers

Steven Parker
Steven Parker
210,850 Points

It looks like you got a bit overly-specific, and each of your character classes represent a different character.

A regex of '[0-4][^5-7][8-9]' will only match 3 consecutive characters where the first one is a digit between 0 and 4 (inclusive), the second one is anything other than 5, 6, or 7, and the last one is either 8 or 9. And of course, there are no instances like that in the test string.

Try making a bit simpler, specify only the requirements, and for a single character.

Steven Parker
Steven Parker
210,850 Points

The instructions say the "pattern matches anything in string except the numbers 5, 6, and 7.", so you really only want to use a single character class, and use it to only exclude those three digits. So you already have the right coding, but it's sandwiched between two other things you don't need.

Jason Smith
Jason Smith
6,946 Points

i was under the impression multiple sets meant multiple queries, can you give me an example of a similar one-set query?

Jason Smith
Jason Smith
6,946 Points

thanks for the hint! that was it