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

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