Quick actions

cmd+k|ctrl+k

Navigation

Languages

Password Regex

Snippet info

Language

Python

Visibility

public

Author

adrianblair1992

Created

2024-11-25T12:16:51.126621Z

Updated

2024-11-25T12:34:09.209396Z

# 8 Char long atleast.
# contains letters, numbers, and symbols

'''
    ^: Start of the string.

    (?=.*[a-z]): At least one lowercase letter.

    (?=.*[A-Z]): At least one uppercase letter.

    (?=.*\d): At least one digit.

    (?=.*[@$!%*?&]): At least one special character from the set @$!%*?&.

    [A-Za-z\d@$!%*?&]{8,}: Matches any combination of the allowed characters, with a minimum length of 8.

    $: End of the string.

    This pattern ensures the password:

    Contains at least one lowercase letter.

    Contains at least one uppercase letter.

    Contains at least one digit.

    Contains at least one special character.

    Is at least 8 characters long.
'''

import re

pattern = re.compile(r"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$")

password = input("Enter a password:")

print(pattern.search(password))
INFO