문제

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.

도움이 되었습니까?

해결책

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

this should do the trick.

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

다른 팁

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

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

Assuming there will be no input like .102123

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top