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

Understanding the question

I don't really understand what the question is asking. I think that it's asking me to find count number of numbers in the string and print the re.search of the numbers that I find. Is this right and if so how do I do that. Do I need another for statement?

import re

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

def numbers( count_, var_str):
    for _ in range(count_):
        return re.search(r'\d', var_str)

2 Answers

Rick Gleitz
Rick Gleitz
42,802 Points

You don't need the for statement, and the return just needs to have the r'\d' multiplied by the count_ parameter. It seems to be asking to find a continuous number of digits in the string. Hope this helps.

4,673 Points

The wording of this challenge was difficult to understand (Challenge 2/2, Regular Expressions, Escapes).