I am currently working on creating a regular expression that can detect both positive and negative floating point numbers of any length. My goal is to store the captured values in an array as double data type. I have attempted the following pattern:
input.match(/^[-+]?(\d*)\.?(\d*)$/)
For example, if my number is -123.432, the expected result should be [-123.432,-123.432]
. Similarly, if my number is 23.45, it should return [23.45,23.45]
.
What would be the ideal regular expression to match both negative and positive floating point numbers and obtain the desired result?