我在将 RegEx 表达式转换为 python 时遇到问题。我知道这'(\\d+)'
是单个整数的表达式,但我不知道如何获得 [2-9] 的整数。
正则表达式如下:
[2-9][p-z][a-h][2-9][a-z]*[p-z][2-9][p-z][2-9][p-z]
这是我目前的表达方式,但由于不够具体,它会产生许多误报:
re1='(\\d+)' # Integer Number 1 re2='([a-z])' # Any Single Word Character (Not Whitespace) 1 re3='([a-z])' # Any Single Word Character (Not Whitespace) 2 re4='(\\d+)' # Integer Number 2 re5='((?:[a-z][a-z]+))' # Word 1 re6='(\\d+)' # Integer Number 3 re7='([a-z])' # Any Single Word Character (Not Whitespace) 3 re8='(.)' # Any Single Character 1 re9='([a-z])' # Any Single Word Character (Not Whitespace) 4
## Regex search for passcodes ## Thanks to Pierluigi Failla
rg = re.compile(re1+re2+re3+re4+re5+re6+re7+re8+re9,re.IGNORECASE|re.DOTALL)
m = rg.search(txt)
if m:
int1=m.group(1)
w1=m.group(2)
w2=m.group(3)
int2=m.group(4)
word1=m.group(5)
int3=m.group(6)
w3=m.group(7)
c1=m.group(8)
w4=m.group(9)
txt2='"'+int1+w1+w2+int2+word1+int3+w3+c1+w4+'"'
return [txt2]