I have below code for replace anything apart from number/ float from a string.
const parseNumbers = strInput => strInput
.trim()
.replace(/^[@#$%^&*()_+}{|{}[\]/<>,.;'"`~a-z!]*/gi, '')
.replace(/[^0-9]+[.][0-9]*/g, "");
The following strings are not working with the above regex:
'644322.abc'
While this works '644322.abc.....' gets converted to 644322
'644322.12ac.....' gets converts to 644322.12
But this does not:
'644322.12ac' gets converted to 644322.12ac
'644322.12-1' remains as is 644322.12-1
I want to replace all characters which are not numbers and keep values as number or float.
644322.12-1? I suppose644322.121, right? Or do you only want to keep max 2 fractional digits?