I am trying to filter a list of strings with regular expressions, as shown in this answer. However the code gives an unexpected result:
In [123]: r = re.compile('[0-9]*')
In [124]: string_list = ['123', 'a', '467','a2_2','322','21']
In [125]: filter(r.match, string_list)
Out[125]: ['123', 'a', '467', 'a2_2', '322_2', '21']
I expected the output to be ['123', '467', '21']
.