

)? – Entire regex expression is optional.The matching either positive or negative sign is optional


We just added the optional positive negative sign in front The regex is the same as the earlier regex. Let’s make it more complex by having it accept a negative or a positive sign. \.\d+ – This captures the part where the integer part is not present and the decimal part is always present.(?:0|\d*)(?:\.\d*)? – This captures the part where the integer part is always present and the decimal part is optional.On a high level, the entire regex has two parts which are in OR relation Let’s first see a simple regex which only matches only the integer, dot, and decimal parts. Any other char before or after the floating-point number.So below are valid floating-point numbers 1.2 The dot and decimal part could be optional if the integer part is present.The integer part could be optional when the decimal part is present.It could have a negative and positive sign.A floating-point number could have below properties
