Why does digits end up empty
The glob expression [^0-9]* matches a non-digit characters [^0-9] and then matches any characters *. Just like echo [^0-9]* would match a file named abc-123.
How to get only the digits from a bash variable?
Remove the erroneous *.
digits=${both//[^0-9]/}