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 Escapes

Dhruv Ghulati
Dhruv Ghulati
1,582 Points

'NoneType' object has no attribute 'group'

Any idea why this is doing this?

escapes.py
import re
def first_number(i):
  return re.match(r'\d',i)

2 Answers

Hi Dhruv,

The challenge is expecting a search, instead of a match.

The function should search, with a regular expression, the first number in the string and return the match object.

Kind Regards

Dhruv Ghulati
Dhruv Ghulati
1,582 Points

I even tried

def first_number(i):
  return re.search(r'/d',i)

And get the same error, which makes me think that it is something to do with the object i. If I put i=str() before my return, I get the same error though...

In your first post, the d was being escaped correctly, with a backslash - now you're using a forward slash, so the program is now looking for the literal string '/d' instead of a number.