Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

Community Beginner ,
Apr 29, 2024 Apr 29, 2024

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

TOPICS
How to
627
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 29, 2024 Apr 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. 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 29, 2024 Apr 29, 2024

hi robert,

 

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

Scherm­afbeelding 2024-04-29 om 12.37.32.png

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 29, 2024 Apr 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

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 29, 2024 Apr 29, 2024

thanks robert.

unfortunately, '[1-9]\d\d\d' finds the first 3 digits in a 4 digit number as well. that should not be the case.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 29, 2024 Apr 29, 2024

Right, add "^" at the beginning - start of paragraph - and "$" at the end:

 

^\d\d\d$

 

00$0

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 29, 2024 Apr 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 29, 2024 Apr 29, 2024

Yeah, word boundary will work as well.

 

@renéb52836404

 

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

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 29, 2024 Apr 29, 2024
LATEST

thanks robert and jm 🙂

both solutions work well.

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines