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

alex albas
seal-mask
.a{fill-rule:evenodd;}techdegree
alex albas
Front End Web Development Techdegree Student 2,190 Points

I can't understand this challenge...

I can't pass this challenge..i think i don't understand so good this challenge...any help would be appreciated! Thanks :)

escapes.py
import re

def first_number (my_string):
  return re.search(r'\d',my_string)
def numbers (count, my_string):
  return re.match(r'\w', my_string) * count

1 Answer

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

numbers() needs to find numbers, not word characters, so you don't want \w.

count is going to be a number. Let's say it's 3. string is going to be a string. It's not important right now. You need to change your regular expression so, if count is 3, the pattern will be '\d\d\d'. Obviously you don't want to account for every possible number, so can you remember or think of a way to repeat a string multiple times?

alex albas
seal-mask
.a{fill-rule:evenodd;}techdegree
alex albas
Front End Web Development Techdegree Student 2,190 Points

yes Kenneth, i.e '=' * 3 it has as result : '===' it is understood, yeah i got it, return re.search(r'\d' * count, my_string) ;) Thanks Kenneth ;)