Skip to main content
Participating Frequently
April 29, 2024
Question

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

  • April 29, 2024
  • 2 replies
  • 648 views

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 has been closed for replies.

2 replies

jmlevy
Community Expert
Community Expert
April 29, 2024

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

Robert at ID-Tasker
Legend
April 29, 2024

Yeah, word boundary will work as well.

 

@renéb52836404

 

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

 

Participating Frequently
April 29, 2024

thanks robert and jm 🙂

both solutions work well.

 

Robert at ID-Tasker
Legend
April 29, 2024

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. 

 

Participating Frequently
April 29, 2024

hi robert,

 

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

Robert at ID-Tasker
Legend
April 29, 2024

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