import rerx = r'\d{1,3}(?:\s[AB])?'s = ['Riverside 456 A', 'Riverside 456']print([re.search(rx, x).group() for x in s])
Standard input is empty
['456 A', '456']
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!