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 trialpathcl
788 Pointscould you provide an expected output?
I can't understand whats the expected function
import re
def first_number(num):
return re.search(r'\d', num)
def numbers(integer, string):
pattern = re.compile(integer * len(string))
return re.match(pattern, string)
1 Answer
Unsubscribed User
3,273 PointsI think I see what you did here.
The challenge is asking you to return "x" number of integers from the string by using something like r"\d" * integer in your search pattern.
Your search pattern on the other hand is not actually a search pattern. After compile you used integer * len(string) which would make python try to compile a single integer and use it as a search pattern in the the re.match call you use on the next line.
I'm going to suggest you look back at what you did to answer the first part of the challenge. What you did there is really close to a solution to this new problem. If you insist on using re.compile which is good practice for repeated searches then treat it the same as the search pattern you use as the first argument of re.search.
If you are looking for a solution I will post one I wrote bellow but try your own again first:
import re
def first_number(num):
return re.search(r"\d", num)
def numbers(integer, string):
return re.search(r"\d" * integer, string)