Jesse
Jesse

Reputation: 3

Adding commas to numbers using regular expressions and find and replace

I'm using Sublime Text 3 right now, working with a large .kml file.

I have hundreds of things that look like this:

<SimpleData name="DECPOPCNT">93971</SimpleData>
<SimpleData name="DECPOPCNT">5673</SimpleData>
<SimpleData name="DECPOPCNT">100971</SimpleData>

That I want to add commas to -- basically replacing the above with:

<SimpleData name="DECPOPCNT">93,971</SimpleData>
<SimpleData name="DECPOPCNT">5,673</SimpleData>
<SimpleData name="DECPOPCNT">100,971</SimpleData>

The numbers are all between 4 and 6 digits, so I basically just need to add a comma in after the hundreds digit in all cases. Any ideas?

Thanks!

Upvotes: 0

Views: 215

Answers (1)

Santiago
Santiago

Reputation: 1745

Use this regex in Find what:

(\d)(\d{3}<)

And in replace statement write this:

$1,$2

Upvotes: 1

Related Questions