I am new to Regex and try to extract a 16x character piece of text from a list of strings.
Sample list:
myString = [' pon-3-1 | UnReg 5A594F4380661123 1234567890 Active',
' pon-3-1 | UnReg 5A594F43805FA456 1234567890 Active',
' pon-3-1 | UnReg 4244434D73B24789 1234567890 Active',
' pon-3-1 | UnReg 5A594F43805FB000 1234567890 Active',
'sw-frombananaramatoyourmama-01'
]
I cannot use a simple regex like (\w{16}) as this will include all text with 16 characters. I also tried (\w+A) which, depending on the characters in the string, don't return the correct results.
newArry = []
for i in myString:
number = re.search('(\w{16})', i)
newArr.append(number[0])
print(newArr)
Returns:
['5A594F4380661123', '5A594F43805FA456', '4244434D73B24789', '5A594F43805FB000', 'frombananaramato']
- I want to extract only:
- 5A594F4380661123
- 5A594F43805FA456
- 4244434D73B24789
- 5A594F43805FB000
Any ideas?
Many thanks in advance