Question

Well the title says it all.I would like to find a regex that allows me to match the remaining decimals after the 4 first decimals. For the moment I've figured out how to match the number and the 4 first decimals.

^\d+\.\d{0,4}$

but it's the remaining figures that I would like to match on negative and positive numbers.

45.46867431 ---> returns 7431.
5.34 ---> returns nothing.
0.0015 ---> returns nothing.
-135.6584312315 ---> returns 312315.
0.008951 returns ---> returns 51.

I need it to be a regex because it's to clean files, not to format it direclty with a script.

Was it helpful?

Solution

(?<=\.\d{4})\d+

this should do the trick.

demo here : http://regex101.com/r/eW8fR6

OTHER TIPS

This will return you the digits after the dot and four digits.

^-?\d+\.\d{4}(\d+)$

Assuming there will be no input like .102123

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top