folgendes Programm
Code: Alles auswählen
import re
def main():
test_string = "AB1234-5678-ABC"
praefix = 'B'
critical_area = '5678'
pattern = re.compile("^(.{1})(.{1})(.{4})(.{1})(.{4})(.{4})$")
regex_test = pattern.match(test_string)
regex_results = [regex_test.group(x) for x in range(7)]
print(regex_results)
if __name__ == '__main__':
main()
Code: Alles auswählen
['AB1234-5678-ABC', 'A', 'B', '1234', '-', '5678', '-ABC']
Code: Alles auswählen
pattern = re.compile("^A({praefix})(.{1})(.{4})(.{1})({critical_area})(.{4})$")
Code: Alles auswählen
Traceback (most recent call last):
File "/home/****/develop/test.py", line 15, in <module>
main()
File "/home/****/develop/test.py", line 11, in main
regex_results = [regex_test.group(x) for x in range(7)]
^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'group'