-2

I have a txt file, need to find words that are min 6 digits, have uppercase and lowercase letters, digits and punctuation marks. What is my mistake with re?

import re
word_list = []
with open('passwords.txt') as f:
    for line in f.readlines():
        word_list += re.findall(r'^?=.*[A-Z])(?=.*[!@#$&*])(?=.*[0-9])(?=.*[a-z]).{6}', line)
RRRRR
  • 1
  • 2
    Missing opening parenthesis `(` after the `^` – ctwheels Feb 27 '18 at 19:51
  • This looks like a password validation regex though, not a word finding regex. If that's the case you should take a look at [Reference - Password Validation](https://stackoverflow.com/questions/48345922/reference-password-validation/) – ctwheels Feb 27 '18 at 19:51
  • 1
    What is the error you're getting? – Jan Feb 27 '18 at 19:58

1 Answers1

0

you can try:

import re
word_list = []
with open('passwords.txt') as f:
    for line in f.readlines():
        word_list += re.findall(r'[0-9a-zA-Z!@#$%^&*]{6}', line)
Buddy
  • 10,874
  • 5
  • 41
  • 58
Binh ED
  • 21
  • 1