考虑以下代码:import re
k=''
regex = re.compile(r'[a-zA-Z]{2}\d{8}')
with open("omg.txt", 'r') as f:
for line in f:
line = line.replace(',', '')
line = line.replace('.', '')
k = regex.findall(line)
#k.append(line)
position = False
if str(k) != '[]': # The `[]` is just the string representation of an empty array
position=True
print(k)
else:
position=False
给定文件(忽略#之后的文本,而不是文件的一部分)AZ23153133
# Empty line
AB12355342
gz # No match
XY93312344
输出将是['AZ23153133']
['AB12355342']
['XY93312344']