import rep = re.compile(r'^PY\s+(\d{4})', re.M)test_str = "PY123\nPY 2015\nPY 2017"print(re.findall(p, test_str))
Standard input is empty
['2015', '2017']
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!