txt中的python正则表达式

时间:2018-02-27 19:49:31

标签: python regex

我有一个txt文件,需要找到最小6位数字,大写和小写字母,数字和标点符号。我的错误是什么?

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)

1 个答案:

答案 0 :(得分:0)

你可以尝试:

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)