我不熟悉regex。我使用的是python2.7和BeautifulSoup4。我想迭代一个特定的正则表达式。在
所需输出:
length : 5 , expression : [a-zA-Z0-9!&#%@]
It should try all possible combinations e.g:
['aaaaa','aaaab','aaaac',...,'aaaaz','aaaaA',...,'aaaaZ','aaaa0','aaaa9','aaaa!','AAA!!']
Moreover this should be possible too. If the expression is orange\d{1}
['orangea','oranges']]
我试过了:
regexInput = "a-z0-9"
#regexInput = "a-zA-Z0-9!@#$%^&"
comb = itertools.permutations(regexInput,passLength)
for x in comb:
''.join(x)
我意识到这是一个完全错误的方法,因为这些只是排列。请帮忙。抱歉解释不好,非常沮丧。在
用于排列或组合的Itertools函数将一系列元素作为第一个参数。它无法为您生成系列(从
a-z
到abc...xyz
)。幸运的是,string
提供了一些常量,比如ascii_letters
,它们包含a-zA-Z
。在如果您的目标是解释正则表达式并生成每个案例。。。这很难,你应该解释为什么?在我们更进一步之前。在
如果你只想得到字母组合:
您可以将
string.ascii_letters
替换为任意系列的字符。在相关问题 更多 >
编程相关推荐