I have been trying to write a RegEx expression that captures examples such as the following:
const decimalTest = new RegExp(/.../);
decimalTest.test("There are 1.2 apples"); // true
decimalTest.test("1.2"); // true
decimalTest.test("0.2"); // true
decimalTest.test(".2"); // true
decimalTest.test("Version 1.2.3 was released"); //false
decimalTest.test("1.2.3.4.5..."); //false
Methods I have tried all seem to fail in one way or another. I am fairly new to RegExp but I thought lookarounds seemed promising for this particular case, but have had no looking in creating a working example. Here was the expression I came up with that seemed to come closest to doing what I was hoping it would do:
/(?<!\d*\.\d)(\d*?\.\d+)(?!\d*\.\d)/
The flaw here was that in an example like 1.2.3, it would match the 2.3. I'm thinking I am just misunderstanding something about what that expression is doing. Any advice, resources, or links that could aid me with this example and RegExp in the future would be appreciated!