1

I want to write a regular expression for the password validation in python where it contains at least one upper case character[A-Z], at least one number[0-9], and would have a length of exactly 8 characters.

I tried this one, but somehow it is not working, can someone please help?

import re
match=re.fullmatch('[(A-K)+(0-9)+(A-Z0-9a-z@)+]{8}','bAlaji12')
if match!=None:
    print(match.group())
else:
    print('No Match found')
Ibo
  • 4,081
  • 6
  • 45
  • 65
  • 2
    Does this answer your question? [Validation of a Password - Python](https://stackoverflow.com/questions/41117733/validation-of-a-password-python). Also related: https://stackoverflow.com/questions/2990654/how-to-test-a-regex-password-in-python; https://stackoverflow.com/questions/46582497/python-regex-for-password-validation – Tomerikoo Jan 27 '20 at 19:07
  • Welcome to SO! `^(?=.*[A-Z])(?=.*\d).{8}$` or do you mean "exactly one digit" and "exactly one upper"? – ggorlen Jan 27 '20 at 19:09
  • @ggorlen: Never seen this kind of usage of look aheads/ look behinds. Can you explain to me how this regex works? Is this the typical way to check if a character group is represented in a string? The whole ```^(?=[GROUP1])(?=[GROUP2])```? – J.Doe Jan 27 '20 at 19:15
  • Yeah, these are lookaheads to ensure that there's at least one upper and one digit. Pretty standard. Re: downvoters... question isn't _great_ but it has a pretty clear description and an attempt, so I don't see a problem. Input/output examples would be nice though and OP could jump on this thread and respond to the requests for clarification. – ggorlen Jan 27 '20 at 19:17

0 Answers0