This works:
var.replace(/[^0-9]+/g, \'\');
That simple snippet will replace anything that is not a number with nothing.
But decimals
If you don't want to catch IP address along with decimals:
var.replace(/[^0-9]+\\.?[0-9]*/g, '');
Which will only catch numerals with one or zero periods