# Using grep to finding long digit series and inserting thin spaces into them

On my page i have a table with over 500 rows, in it one column where all cells contain a different numbers, such as 55123, 666000, 3000 and 1459000 (figures for sums of money). I would need to insert thin spaces in the numbers for them to be easier to read, according to the following scheme:

Seven digits in a row is changed to: d ddd ddd (eg 1 459 000, d=digit)

six to: ddd ddd (eg. 666 000)

five to: dd ddd (eg. 55 123)

Four to: d ddd (eg. 3000)

using find/change I am able to find all instances of for example 7 digits in a row with the grep line \d{7} but i am lost at having a command for how to "change" using the found numbers and adding a thin space at the right positions.

Is there a way of writing a script or a find/change query for this operation for doing this anywhere in the text (or just the table)? Any tips on this are much appreciated!

• Hey Julius, welcome to GD.SE! If you have any questions about how the site works, have a look at the help center or feel free to ping one of us in Graphic Design Chat once your reputation reaches 20. Keep contributing and enjoy the site! Commented Oct 20, 2015 at 18:01

There is a bug in the matching engine (at least in my indesign) we will fix this first.

• Find:

`(.)\Z`

• Replace

`\$1:`

• Replace All

Ok now we have a anchor at the end of story. Now for the magic:

• Find:

`(\d)(?=(\d\d\d)+(:|\s))`

Explanation match any digit followed by any number triplet of digits and : or any whitespace

• Replace

`\$1~<`

Number and thin space

• Replace All

And now let us fix end marker back:

• Find:

`:\d`

• Replace

leave empty

• Replace All

Done.

PS: you can try if `(\d)(?=(\d\d\d)+\Z)` works, it does not work on my machine.