Back to Freecodecamp

Step 32

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

latest1.4 KB
Original Source

--description--

You can obtain the same result without using the compile() function. Modify your pattern variable into the literal string 'l+'. Then, change the print() call to print re.search(pattern, quote).

--hints--

You should modify your pattern variable into the literal string 'l+'.

js
({ test: () => assert.equal(__userGlobals.get("pattern"), "l+") })

You should print re.search(pattern, quote).

js
({ test: () => assert.match(code, /^print\s*\(\s*re\.search\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 = re.compile('l+')
quote = 'Not all those who wander are lost.'
print(pattern.search(quote))
--fcc-editable-region--