Skip to main content
Participating Frequently
Apr 29, 2024 7:46 AM UTC
Question

indesign grep : 3 and 4 digit numbers to 5 digits by adding zeros

hello,

 

in an indesign catalog i would like to change 3 and 4 digit numbers to 5 digits.

3 digit numbers should get 2 zeros up front, 4 digit numbers should get one zero.

5 digit numbers should remain unchanged.

f.i. :

465 -> 00465

5567 -> 05567

23167 -> 23167

 

i'm pretty sure this can be done by a grep find and replace, but i don't know how.

any help is appreciated.

 

rené bosch

This topic is closed to new replies. Start a new post to keep the conversation going.

8 replies

jmlevy
Community Expert
Community Expert
Apr 29, 2024 12:43 PM UTC

Try this, and as @Robert at ID-Tasker wrote, you'll need 2 steps:

For the 3 digits numbers

Find: \b\d{3}\b

Replace: 00$0

 

For the 4 digits numbers

Find: \b\d{4}\b

Replace: 0$0

Translate
Robert at ID-Tasker
Legend
Apr 29, 2024 1:00 PM UTC

Yeah, word boundary will work as well.

 

@renéb52836404

 

And to be even more "direct" - you can specify ParaStyle.

 

Translate
Participating Frequently
Apr 29, 2024 3:13 PM UTC

thanks robert and jm 🙂

both solutions work well.

 

Translate
Robert at ID-Tasker
Legend
Apr 29, 2024 10:24 AM UTC

Yes, but knowing current "surrounding" of the digits would be helpful - can you share a screenshot?

 

Would have to be done in two steps anyway. 

 

Translate
Participating Frequently
Apr 29, 2024 10:40 AM UTC

hi robert,

 

the numbers are in a table and have paragraph styles. here is a screenshot, it concerns the bold numbers only :

Translate
Robert at ID-Tasker
Legend
Apr 29, 2024 10:55 AM UTC

I'm on my phone so I'll just brainstorm... 

 

[1-9]\d\d\d

 

00$0

 

and

 

[1-9]\d\d\d\d

 

0$0

 

Translate