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

Mar Bocatcat
Mar Bocatcat
7,405 Points

Re.Expressions

What am i missing here? Any advice?

negate.py
import re

string = '1234567890'

def good_numbers(string):
  return re.findall(r'[\w\d][^567]', string, re.I)

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

Hi Mar,

There are two issues with your solution. First, the task asks only to create a variable named good_numbers, not a function.

Second, your regex is overly complicated for the task. By combining two character sets your regex r'[\w\d][^567]' says:

`[any word or decimal character][not followed by 5 6 or 7]' this means the "7" will still be found "good" because it is follow by "8".

Your regex need only say `[not a 5, 6 or 7]'. This can be accomplished using:

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

The re.I is not needed since there is no character case to ignore.

Best of luck. Keep Coding!

Mar Bocatcat
Mar Bocatcat
7,405 Points

Thank you ! I need to read the details more!