Filter a string in Python by removing all alphabets and keeping only the numbers.
my_string = "hey3this5is4my2string1"
def filter_string(str):
    str = ''.join(x for x in str if x.isdigit())
    return str  

my_string = "hey3this5is4my2string1"
print(filter_string(my_string))