CreativePro Forum
Join our community of graphic designers, publishers, and production artists from around the world. Our members-only forum is a great place to discuss challenges and find solutions!
- You must be logged in to reply to this topic.Login
Adding spaces to large figures ? with GREP?
- This topic has 11 replies, 5 voices, and was last updated 11 years, 2 months ago by
Anonymous.
-
AuthorPosts
-
-
July 29, 2013 at 5:11 am #34450
Olaf Mueller
MemberHello,
I have a series of tables with type/numbers differing style formats. I want to add a space in between every third number of figures larger than 4 digits (e.g. 1 234 567 instead of 1234567).
Is there a way to automate such a (laborious) task? I was thinking of GREP but have no experience with it.
Thanks for any handy hints!
Hans Mueller
-
July 29, 2013 at 8:12 am #34463
Justin Sligh
MemberHans,
If your numbers included a decimal place or more specifically a period, you could use a Grep Style to take care of the issue. The expression would be:
\d(?=(\d\d\d)+\D)
The associated character style controls the space between through “tracking”. Setting it to 150 or 200 should suffice.
This expression is saying, Look for a single digit that has one or more three digits groups followed by anything but a digit (e.g, a period). Using \D would allow it to pick up on line breaks and allow you to style whole numbers outside of tables when these numbers are immediately followed by a line break.Else, you will need to use a Grep Find/Replace. The following expression will find the numbers:
Grep Find:
(?<=\d)\d\d\d(?!\d)Grep Replace:
$0 There is a space before the $One of these came from jongware. I don’t remember which.
-
July 30, 2013 at 3:57 am #34491
Masood Ahmad
ParticipantHi Justin,
I am also trying my hands on the GREP and while checking your code at my end, I found that “(?<=\d)\d\d\d(?!\d)” expression will only find the last three digits from a list of numbers. For example in a number 123456789, the expression will only select 789, i.e. the last three digits and it will then move on for the next search.
However, if you use your GREP expression shown above “\d(?=(\d\d\d)+\D)” in the Find What panel and replace it with the character style, you just suggested above, then the search will find all the groups of 3 digits starting from the ending position. For example in a number 123456789, it will become 123 456 789.
Hans, in addition to Justin, I would like to add a GREP expression, in case you need to create a 3 digit group from the beginning of the numbers, For example: 1234567, it will become 123 456 7.
Grep Find:
(\d\d\d)(?=\d)Grep Replace:
$0 (please note that there is a space after $0)Thanks
-
September 19, 2013 at 9:49 am #65412
Olaf Mueller
MemberHello, Masood,
I only now had the opportunity to check all of your fine hints. Some work, some don’t, e.g. «\d(?=(\d\d\d)+\D)» only finds the first digit in at least 4 figures comprising group. Using «(\d\d\d)(?=\d)» works fine and I’d like to add the condition that the group of figures that should be search for groups of three digits should comprise at least 5 digits.
Would you perchance have another hint there, too?
Thanks anyway and to all!
-
September 19, 2013 at 7:50 am #65403
Olaf Mueller
MemberThanks for the hint, Justin. I finally got to try it out and it works fine, even when I have to apply twice or more to space to all three-figure combos.
-
-
July 30, 2013 at 12:17 am #34489
Olaf Mueller
MemberThank you very much, Justin,
for your high profile answer. I’m not working on the project right now but I will try that solution for sure!
Thanks again.
-
July 30, 2013 at 7:17 am #34494
Justin Sligh
MemberMasood,
Good catch. I forgot to mention that the Grep Find/Replace cannot complete the process in one instance. You need to keep pressing Replace All until no matches are found.
Your suggestion for Grep Find/Replace with the style works. However, it will not pick up numbers at the end of a paragraph. I would have assumed that using a $ in lieu of \D would do the trick but it does not work. Im not sure how to handle that situation.
Thanks for the response in regard to the adding space in the opposite direction.
-
July 30, 2013 at 8:26 am #34496
Masood Ahmad
ParticipantThanks Justin. I am just a beginner. I checked both the expressions (given below), both are working fine even if the numbers are at the end of a paragraph with or without a period. I tested it both way i.e. with paragraph style and with Find/Change.
Here is the text I was using for testing purpose:
ABC is a US-owned company with over 40 years 12345678 experience in the creative industries. We provide 12345 mission critical, creative production services to 123456 newspaper and magazine publishers, 123456 corporations, catalogue retailers, SME?s, packag 123456789 and 1234567890 pre-media companies 123456789.Find:
(\d\d\d)(?=\d)Replace:
$0and
Find:
\d(?=(\d\d\d)+\D)Replace:
$0 or character style -
July 30, 2013 at 10:01 am #34506
Justin Sligh
MemberMasood,
In situations where the paragraph does not end with a punctuation. Such the last line in the following:
65 879 758
86 785 789
58787878Any person who has wrapped their had around Grep Styles is no beginner in my book!
-
July 30, 2013 at 10:09 am #34507
Theunis De Jong
MemberAFIK (Away From InDesign Keyboard) at the moment, but you can try this:
\d(?=(\d\d\d)+(?!\d))
instead of Masood’s \d(?=(\d\d\d)+\D)
In essence, it means the same — a digit followed by 3 digits followed by NOT a digit — but there is an essential difference. “\D” is “a character which is not a digit”, but “(?!\d)” means “not a digit”. That last one is also true if *nothing* follows :-)
-
July 31, 2013 at 1:42 am #64597
Masood Ahmad
ParticipantIt seems I am missing something or unable to understand what Justin is trying to say. I tried both ways i.e. a para ending with or without a punctuation, the grep mentioned by Justin in #34463 “\d(?=(\d\d\d)+\D)” is working fine. Also the Jongware’s expression is giving me the same output both ways.
Here is my Input and Output:
Text before Find and Replace command:
ABC is a US-owned company with over 40 years 12345678 experience in the creative industries. We provide 12345 mission critical, creative production services to 123456 newspaper and magazine publishers, 123456 corporations, catalogue retailers, SME’s, packag 123456789 and 1234567890 pre-media companies 123456789
58787878ABC is a US-owned company with over 40 years 12345678 experience in the creative industries. We provide 12345 mission critical, creative production services to 123456 newspaper and magazine publishers, 123456 corporations, catalogue retailers, SME’s, packag 123456789 and 1234567890 pre-media companies 123456789.
58787878.Text after the Find and Replace command using the expression:
Find:
\d(?=(\d\d\d)+\D)
\d(?=(\d\d\d)+(?!\d))Replace with:
$0 (with space after $0)ABC is a US-owned company with over 40 years 12 345 678 experience in the creative industries. We provide 12 345 mission critical, creative production services to 123 456 newspaper and magazine publishers, 123 456 corporations, catalogue retailers, SME’s, packag 123 456 789 and 1 234 567 890 pre-media companies 123 456 789
58 787 878ABC is a US-owned company with over 40 years 12 345 678 experience in the creative industries. We provide 12 345 mission critical, creative production services to 123 456 newspaper and magazine publishers, 123 456 corporations, catalogue retailers, SME’s, packag 123 456 789 and 1 234 567 890 pre-media companies 123 456 789.
58 787 878.I think what finally matters is the output, which has been achieved. Happy GREPing…
-
-
November 7, 2014 at 11:22 pm #71510
Anonymous
InactiveHere is the correct GREP syntax:
\d(?=((\d{3})+))
In clear words: a digit, followed by a multiple of a three-digit-group, followed by a “end of word”. You can enter this string into a GREP style within your paragraph style options as well in order to have digits formatted fully automatically, using a character style that applies eg “150” of tracking.
Two important remarks:
1. The “” does NOT honor the “end of story” character. Therefore the GREP expression will not work at the very end of your story. So if you use this GREP expression as a GREP style in your paragraph style, you have to make sure that there is eg an additional space character behind a figure at the end of the story.
2. Of course, you dont wan’t to have the year “2014” styled as “2 014”. That’s why you need a second character style that applies a tracking of “0” (zero). ([None] will NOT work.) Apply this character style manually to the string “2014” if necessary, using an appropriate Find/Change operation.
Rudi
-
-
AuthorPosts
- The forum ‘General InDesign Topics (CLOSED)’ is closed to new topics and replies.
