Inserting Commas in Large Numbers Using GREP
Question: “I have an InDesign file with lots of tables with numbers. The client sent data/numbers without commas, but now they are asking that commas be included. Is there a GREP code to insert commas in numerals where needed? For example, I need to update 25309 to 25,309 and 856194 to 856,194.”
Answer: Yes, there is! You can do it quite simply, using multiple rounds of Find/Replace with GREP. Here’s how it works:
. . . .This article from CreativePro Magazine is for members only. To continue reading, please log in above, or sign up for a membership today! Thanks for supporting CreativePro!
This is great! And if the numbers are in the middle of a paragraph (instead of at the end of a paragraph), you could replace the $ symbol with
\b
which is the code for any word break)Yes, that is a more general expression, which I should have thought of in the first place! It requires
/b
rather than just b, so the search expression in full is:(?<=\d)(\d{3})\b
A single expression will add commas in any length number in a single pass:
Find what: (d{1,3})(?=(ddd)+b)
Change to: $1,
P.
The four ds and the b should be preceded by a backslash, naturally.
In Find: d{1,3}(?=(d{3})+b)
in Change: $0,
Much more elegant than my quick-and-dirty answer. Thanks, Peter!
Find: (d{1,3})(?=(d{3})+b)
Replace: $1.
Edit: Very similar to the reply of Dhafir. (saw that afterwards ;) )
with backslashes before the “d” and “b” naturally.