tonumber returns nil with strings that contains something else than spaces, digits, one dot and one hyphen.
Unlike paseInt/parseFloat that return the number at the beginning of the string, not matter what characters comes after it.

That's what the regex is for, it detects characters other than spaces, digits, dot and hyphen and make tonumber returns null when one of them is found.