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

Evan Mnatsekanov
Evan Mnatsekanov
1,761 Points

How would I separate those numbers?

negate.py
import re

string = '1234567890'

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

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,029 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!!!