Back

If your email is not recognized and you believe it should be, please contact us.

  • You must be logged in to reply to this topic.Login

GREP or sth else? Number – space – number.

Return to Member Forum

  • Author
    Posts
    • #78069

      Hello,
      I’ve got over 300 tables placed from Word doc. The numbers in cells are mostly 6 or 7 digits each. But some of them are 2 or 3. And sometimes they are not integer numbers. So, we have eg.: 1,25 or 3457862, or 256 etc. What I’d like to achieve is to insert spaces between each three digits in numbers containing more than 3 of them to separate “thousands”. That’s the way we do it in Poland. As well as using comas to as a sign of fraction.
      It’s obvious I’d like to apply some automatic action. Running CS6.
      Any ideas, ID fellows?

    • #78103
      Aaron Troia
      Participant

      Good question Jerzy, I was trying to figure it out and had to resort to Google to find others with the same issue, and I found one that should work for you.

      Find: (\d)(?=(\d\d\d)+)
      Replace: $1(insert a space)

      Let me know if you have any issues. Here’s the forum post where I found it for reference, https://forums.adobe.com/thread/1458885

    • #78104
      Aaron Troia
      Participant

      I just realized that this GREP only works for the whole numbers and not the fractions, I’m trying to figure out a way that it will work with the fractions, but so far I haven’t had any luck.

    • #78124
      Peter Kahrel
      Participant

      Insertion of thousand separators goes back to Friedl’s ‘Regular Expressions’. The one here is a slight variation in order to deal with the decimal part. \x20 is the space character.

      Find what: (\d)(?=(\d\d\d)+[,]?)
      Change to: $1\x20

      Peter

    • #78130
      Peter Kahrel
      Participant

      Forgot to mention that the GREP replacement in the previous post doesn’t work if a number is the last text in a cell or a story. To make it work everywhere you’d have to add a single symbol at the end of numbers at cell- and story-end, then run the above query, and finally remove that added symbol. For that symbol I use a hair space to reduce the impact on the document.

      So you’d have three queries:

      (Place a hair space at the end of each cell and each story)
      Find what: (\d)\Z
      Change to: $1~%

      (Insert the thousands separators)
      Find what: (\d)(?=(\d\d\d)+,?)
      Change to: $1\x20

      (Remove the hair spaces at the end of cells and stories)
      Find what: ~%\Z
      Change to: <nothing>

      To make running sequences of GREP queries a bit easier, you can use this script:
      https://www.kahrel.plus.com/indesign/grep_query_runner.html

      Peter

Viewing 4 reply threads
  • The forum ‘General InDesign Topics (CLOSED)’ is closed to new topics and replies.
Forum Ads