I am using a simple regex [^0-9.] that doesn't match any numbers between 0 to 9 and a period in my given string and matches the rest, and I replace that with empty string and then convert my valid value (integer or double) in string format into an integer or double.
For example:
'123A.478' => '123.478'
'123.48' => '123.48'
'123AX' => '123'
I want to also handle negative valued strings as well i.e. if a string has '-123', I want to retain it. So, I need to convert the strings as follows:
'--123.46' => '-123.46',
'123A-.46' => '123.46',
'-123--.46' => '-123.46',
'A-123-.46' => '-123.46'
I tried using a quantifier but I was unable to build a correct regex with my existing one.
Is there any way I can achieve this using regex?