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

Alex Rendon
Alex Rendon
7,498 Points

Where is my error in this regular expression?

I have to match all the numbers in the string, except "567". I except the three numbers with this "^", but I have an error and I don't know what I have to do. Thanks.

negate.py
import re

string = '1234567890'
good_numbers = re.findall(r'\w+[^567]', string)

1 Answer

Alex Rendon
Alex Rendon
7,498 Points

The error still appears, Now the output is: "12347890" That excluded only the numbers "56", but the "7" appears. Why?

Bryan Manhollan
Bryan Manhollan
Courses Plus Student 7,863 Points

This passes for me.

import re

string = '1234567890'


good_numbers = re.findall(r'[^567]', string)
Alex Rendon
Alex Rendon
7,498 Points

Oh, thanks jajaja. That error... :P