txt中的python正则表达式

问题描述 投票:-2回答:1

我有一个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)
python regex
1个回答
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)
© www.soinside.com 2019 - 2024. All rights reserved.