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

sarvienn thevendran
sarvienn thevendran
734 Points

re.search : how is this supposed to work?

in this re.search function I dont know where i can place my raw source.. as in doesn't the re.search function need a place you want it to look at? i am getting an erroe saying it is missing a positional argument

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

def numbers(cnt,str):
    return re.search(r'\str' * cnt)

1 Answer

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,028 Points

The numbers function isn't quite right. I think what you need to do there is cast the return value as a string, so you get the required number of numbers in your result.

So... the reference to re. is simply calling the regular expression library so you can use search and match methods.

You're right to try and multiply in your return. But you just need a simple regular expression and then reference your function arguments in your call to search.

So simply...

    return re.search(r'\d' * cnt, str)