I am trying to match decimals for both strings and floats. Noticed that the below RegEx matches floats ending with a period(.) as well which isn't expected.
const regex = RegExp("^(\\d*\\.)?\\d+$");
arrTest = ["3.", 3., "4.", 4., "5.5", 5.5];
arrTest.forEach(element => {
console.log(regex.test(element))
});
/*
Result
=======
"3." - False
3. - True (Expecting false since regex should end with a number)
"4." - False
4. - True (Expecting false since regex should end with a number)
"5.5" - True
5.5 - True
*/