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

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

escapes.py
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
MOD
Jonathan Grieve
Treehouse Moderator 91,252 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)