import re s = "xaz xazx xaxsza zsxdaszdx zasxz xaaz xaaaz"print([x for x in s.split() if x.startswith('x') and x.endswith('z')])
Standard input is empty
['xaz', 'xaaz', 'xaaaz']
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!