stringTxt='vg2v145jhvk34j21vkj1h2v345j1hv' out='' for i in stringTxt: if i.isdigit(): out+=i print(out)