I wrote the following code:
import re
strings = []
strings.append('merchant ID 1234, device ID 45678, serial# 123456789')
strings.append('merchant ID 8765, user ID 531476, serial# 87654321')
strings.append('merchant ID 1234, device ID 4567, serial# 123456789')
strings.append('merchant ID 1234#56, device ID 45678, serial# 123456789')
strings.append('device ID 4567, merchant ID 8765, user ID 531476, serial# 87654321')
for n in strings:
expr = re.findall(r'merchant\sID\s\d+|device\sID\s\d+', n);
if len(expr) == 2:
print(n)
The mission is to scan the 5 strings and print only the strings which got 'merchant ID' and 'device ID' and that the ID number is legid (only degits). So from those 5 strings it should print only the first, the third and the fifth strings. The code i wrote prints also the forth string.
How do i fix the code to recognize that the set of digits 1234#56 is not legit?