I need to write a regex that will capture all of the following numbers from a sample text:
2.5
5
0.2
.5
Assuming its not going to be more than 2 digits on either side of the decimal point, what regex do i use?
thanks.
This should work.
(\d*\.?\d+)
It means
(
begin capture group\d*
any digit zero or more times\.?
a period zero or one times (i.e. it is optional)\d+
any digit one ore more times)
end capture groupIt will match all the number you listed and capture them in $1
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With