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 Escapes

Ashley Justice
Ashley Justice
81 Points

I keep getting a None group error. Anyone else have this issue?

I've tried adding a group in, but it just says Try Again!

escapes.py
import re

def first_number (String):
    result.group(1) = re.search(r'\d', String)
    print(result.group(1))

1 Answer

Moosa Bonomali
Moosa Bonomali
6,297 Points

The challenge requires that you search for the 1st number and return the match object. Rather than printing the result of the search , you should return the result of the search like this;

def first_number (String):
    result = re.search(r'\d', String)
    return result

or if you wanted to simplify, you can also this

def first_number (String):
    return re.search(r'\d', String)

If a match is not found the returned value will be None