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

Abdulkadir Kollere
Abdulkadir Kollere
1,723 Points

'_sre.SRE_Match' object has no attribute 'count'

Hi! The code below does not let me pass the challenge. I would honestly say that I do not even get what the challenge wants specifically. Which integer are we going to multiply with, is it the one in the argument or the number of integers in the string (sentence in my case).

Any help will be appreciated.

escapes.py
import re
def first_number(string):
    output = re.search(r'\d', string)
    return output

def numbers(count, sentence):
    pattern = re.search(r'\d'* count, sentence)
    return pattern.count()

1 Answer

Umesh Ravji
Umesh Ravji
42,386 Points

Hi Abdulkadir, your pretty much there, just make sure you are returning the right thing.

Just like the first question, you have to return the result from the re.search method. The value of count is used to create a sequence of \d that is the same length as count.

def numbers(count, string):
    search = re.search(r'\d' * count, string)
    return search