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 Negated Numbers

keith rezendes
keith rezendes
4,459 Points

What's up with the challenges lately, nothing seems to work and the error messages don't help.

See my code and more importantly, the error message, don't change string, I didn't even touch it.

negate.py
import re

string = '1234567890'

good_numbers = re.findall(r'[^567]', string)

1 Answer

The problem is you're checking each character to see if it's a '5', '6' or '7' and then returning the character. If you run that in Python you'll see that the response is ['1', '2', '3', '4', '8', '9', '0'], which is not what is wanted. It should return ['1234', '890']. To get that you need to match groups of at least 1 character that isn't a '5', '6' or '7'. The correct solution is

good_numbers = re.findall(r"[^567]+", string)