This is question 11 from the regex101 quiz
I have been trying to figure out a solution to solve the test case below from failing. Can someone help with this?
Test 60/89: Just a dot is not a valid floating number.
I am using the regex below.
/^[ -]?\d*([.,]\d*)?([Ee][ -]?\d )?$/g
CodePudding user response:
You can use
/^[- ]?(\d [,.]|\d*[.,]?\d )(e[- ]?\d )?$/i
Details:
^- start of string[- ]?- an optional-or(\d [,.]|\d*[.,]?\d )- either one or more digits, then,or., or zero or more digits, an optional.or,` and then one or more digits(e[- ]?\d )?- an optional occurrence ofe, then an optional-orand then one or more digits$- end of string.
