Back to Freecodecamp

Step 33

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

latest1.3 KB
Original Source

--description--

To check that the generated password meets the required features, you are going to use the findall() function from the re module. It's similar to search but it returns a list with all the occurrences of the matched pattern.

Replace the search() call with findall() and check the output.

--hints--

You should modify your existing print() call replacing search() with findall().

js
({ test: () => assert.match(code, /^print\s*\(\s*re\.findall\s*\(\s*pattern\s*,\s*quote\s*\)\s*\)/m) })

--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 = 'l+'
quote = 'Not all those who wander are lost.'
print(re.search(pattern, quote))
--fcc-editable-region--