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

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,861 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