I recently came across a function in a library that uses
String(value).replace(/[^0-9.-]/g, '')
to filter out illegal characters and return the legal number. I'm having trouble understanding how this works and what exactly gets replaced. At first glance, it seems like nothing would be replaced.
Here's an example:
String("1.absd").replace(/[^0-9.-]/g, '')
// '1.'