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

Ron Tovbin
seal-mask
.a{fill-rule:evenodd;}techdegree
Ron Tovbin
Python Web Development Techdegree Student 6,268 Points

Getting stuck here

Any help here would be appreciated.

negate.py
import re

string = '1234567890'

good_numbers = re.findall(r"""
               \d+
               [^5678]+
               """,string,re.X)

2 Answers

David Deberry
David Deberry
5,447 Points

Hey I searched and found this as an answer. Do not upvote my answer because sadly it is not my code so I do not deserve it lol But I hope this helps.

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

I think you might be overcomplicating things…

Just use the negated character class ([^notme]). You don't need any modifiers.

Also, I think the range of characters you're not meant to include is wrong. Your code has 5678, but it should only be 567.

Let us know how it goes!