Replacing a number with the first four digits

A place to try and solve your RegEx problems.
Post Reply
rodrigoef
Posts: 1
Joined: Sat Aug 08, 2015 2:43 am

Replacing a number with the first four digits

Post by rodrigoef »

Hello guys.

I have a list of numbers (geocoordinates) and the number of digits varies. I need to search the ones with more than four digits after the point and replace them with the first four digits only.

example: 48.655483275
I need to replace with 48.6554

I'm using [0-9]{5,}, and this found all the numbers with more than four digits after the point, but I'm failing in replace the number with the first four digits.

thanks
User avatar
DigitalVolcano
Site Admin
Posts: 1717
Joined: Thu Jun 09, 2011 10:04 am

Re: Replacing a number with the first four digits

Post by DigitalVolcano »

This should work

Regex

Code: Select all

.([0-9]{4})[0-9]{1,}
Replace

Code: Select all

.$1
Try it in the regex tester
silentguy
Posts: 6
Joined: Fri Dec 12, 2014 10:21 am

Re: Replacing a number with the first four digits

Post by silentguy »

DigitalVolcano wrote:This should work

Regex

Code: Select all

.([0-9]{4})[0-9]{1,}
Replace

Code: Select all

.$1
Try it in the regex tester
You forgot to escape the . ;-)
Post Reply