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!

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

How would I separate those numbers?

import re

string = '1234567890'

def good_numbers(string):
    return(re.findall(r'\d', string))

1 Answer

Chris Freeman
Chris Freeman
Treehouse Moderator 68,404 Points

Hey Evan Mnatsekanov, you’ve started in the right direction.

The pattern currently matches any single digit. The task is to match any character (number or letter) except the numbers 5,6 and 7.

To create a character class to represent a single 5, 6, or 7, enclose these characters within square brackets: [567]

To match anything else outside of a specific character set, add a negation ^ as the first character: [^567]

Two additional corrections:

  • the task is to create (as in assign to) a variable good_numbers. You have created a function of that name instead.
  • return is not a function. It should be followed by a space and the return value need not be wrapped in parentheses.

Post back if you need more help. Good luck!!!