Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how do i search lboth length, letters numbers and symbols:@#$% with regex?

what is wrong here?

import re


pattern = re.compile ('^\w@#$%{8,}')

password = '12345abcd@#$%'

x = pattern.search(password)

print (x)

print (len(password))

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You didn’t escape the $ which has a special meaning in a regular expression and didn’t put the allowed characters in square brackets to allow any of them.

This: ^[\w@#\$%]{8,} is the modified version of the regex which matches the password.

I suggest you check your regular expressions here: https://regex101.com/r/ldvJLf/1 . This site explains in detail the meaning of all single elements of the regular expression, so you can directly see what is wrong if things doesn’t work as you expected.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading