Learn Regular Expressions by Building a Password Generator - Step 42

Tell us what’s happening:

Describe your issue in detail here.
The instructions say the following:
The dot character is a wildcard that matches any character in a string — except for a newline character by default. Modify pattern to match the entire string. Use a . followed by the + quantifier.
I keep on getting an error code that says the following:
Sorry, your code does not pass. You’re getting there.

You should modify your pattern variable to match the whole quote string.
I have tried several things including ‘pattern = ‘[^a-z]t.+’’, ‘pattern = ‘[^a-z]t.+t’’, ‘pattern = ‘[a-z]t.+’’, ‘pattern = ‘[^a-z]t.+t’’, ‘pattern = ‘[^a-z]t.t+’’, ‘pattern = ‘[^a-z].t+’’, ‘pattern = ‘. [^a-z]t+’’ etc…
Can someone please explain what to do for me?

Your code so far

import re
import secrets
import string

def generate_password(length, nums, special_chars, uppercase, lowercase):
    # Define the possible characters for the password
    letters = string.ascii_letters
    digits = string.digits
    symbols = string.punctuation

    # Combine all characters
    all_characters = letters + digits + symbols

    while True:
        password = ''
        # Generate password
        for _ in range(length):
            password += secrets.choice(all_characters)
        constraints = [
            (nums, '[0-9]'),
            (lowercase, '[a-z]'),
            (uppercase, '[A-Z]'),
            (special_chars, '')

    return password
# new_password = generate_password(8)
# print(new_password)

# User Editable Region
# I need help with this line of code
pattern = '[^a-z].+t'
# I don’t understand it.
quote = 'Not all those who wander are lost.'
print(re.findall(pattern, quote))
# User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.3.1 Safari/605.1.15

Challenge Information:

Learn Regular Expressions by Building a Password Generator - Step 42

You appear to have created this post without editing the template. Please edit your post to Tell us what’s happening in your own words.

Try putting your regex and test string into this site:


It will explain each part of the regex and show which part of the string it’s matching.

At the moment your regex matches the sentence, but does not include the period at the end.

1 Like

Thanks :slight_smile: I appreciate the help.
That website helped me figure it out. :+1:
I will make sure to try to give my input if you ever need any help.

1 Like