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 trialAnish Walawalkar
8,534 PointsPython regexp problem. re.search(), didnt get the correct match
dont know exactly what the problem with my re.search() is in numbers()? Question: Write a function numbers() that takes 2 arguments, a counter and a string, returns a search object containing the count # of characters
import re
def first_number(string):
return re.search('\d', string)
def numbers(count, string):
return re.search(r"\w"*count, string)
2 Answers
Robert Richey
Courses Plus Student 16,352 PointsHi Anish,
The pattern needs to match numbers only, not alphanumeric characters.
- Return a match for exactly
count
numbers in the string
Unsubscribed User
3,273 PointsLook at your search pattern in numbers:
+What does \w return?
+What is the question asking you to return?
Ira Bradley
12,976 PointsIra Bradley
12,976 PointsIt shouldn't be
\w
- it should be\d
like this: