Learn Regular Expressions by Building a Password Generator - Step 47

Tell us what’s happening:

Now I am getting a little tired about this.
If it really wants me to call this anything special, this should be said in the assignment.
It asks me to add a fourth pattern to match any and combine the ones I have. Okey

I tied adding one, I removed the old ones and just had this one, but nothing is getting accepted.
Anyone have any clue? Is it the naming? Is it that I need them all + the new one or what? I feel the explanation in the assignment here could be so much better than what it is.

constraints = [
            (non_alphanumeric, r'[^a-zA-Z0-9]'),
            (special_chars, r''),
        ]

I have called it char, character, non_alphanumeric, pattern etc.

Also had this:

constraints = [
            (nums, r'\d'),
            (lowercase, r'[a-z]'),
            (uppercase, r'[A-Z]'),
            (special_chars, r'')
        ]

And then just added the new pattern to these so there is a 5th one inside the constraints etc. But I am not getting anywhere

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)

# User Editable Region

        constraints = [
            (non_alphanumeric, r'[^a-zA-Z0-9]'),
            (special_chars, r''),
        ]        

# User Editable Region

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

pattern = r'\.'
quote = 'Not all those who wander are lost.'
# print(re.findall(pattern, quote))

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:123.0) Gecko/20100101 Firefox/123.0

Challenge Information:

Learn Regular Expressions by Building a Password Generator - Step 47

I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

I suggest you reset the step, it looks like something is missing!

this is the code you find in the editable region when you start with this step:

        constraints = [
            (nums, r'\d'),
            (lowercase, r'[a-z]'),
            (uppercase, r'[A-Z]'),
            (special_chars, r'')
        ]   

And you need to write the pattern in the fourth tuple

It’s called special_chars already, you need to edit that one.

1            (nums, r'\d'),
  2          (lowercase, r'[a-z]'),
    3        (uppercase, r'[A-Z]'),
      4      (special_chars, r'')

I have submitted an issue stating:
I believe a clearer request could had been issue, like:

Now, modify the given fourth member of the array constraints to form a pattern that matches any non-alphanumeric character. Combine the a-z, A-Z, and 0-9 ranges into a single character class and add a ^ as the first character to negate the pattern.

3 Likes