Back to Freecodecamp

Step 31

curriculum/challenges/english/blocks/learn-regular-expressions-by-building-a-password-generator/6564c67db26c417561ab510d.md

latest1.3 KB
Original Source

--description--

As you can see from the output, now your regex matches the first l inside the string.

In your pattern, you can add a quantifier after a character to specify how many times that character should be repeated. For example, the + quantifier means it should repeat one or more times.

Add a + quantifier to your pattern.

--hints--

You should modify your pattern variable into re.compile('l+').

js
({ test: () => assert(runPython(`
    import re
    pattern == re.compile('l+')
  `))
})

--seed--

--seed-contents--

py
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, '')
        ]        

    return password
    
# new_password = generate_password(8)
# print(new_password)
--fcc-editable-region--
pattern = re.compile('l')
quote = 'Not all those who wander are lost.'
print(pattern.search(quote))
--fcc-editable-region--