Copy link to clipboard
Copied
I'm working on a large document (200+ pages) and want to use GREP styles to automate formatting, such as applying character styles to dates, numbers, or specific patterns. However, I'm concerned about potential performance issues or unintended formatting. Are there any tips or best practices for setting up GREP styles efficiently in long documents? Should I limit their use, or are there specific patterns that are known to cause slowdowns?
Copy link to clipboard
Copied
Never done that myself, but interesting thought. For me, this would be too fuzzy, too general to auto-format certain patterns of text because it would be applied to everything the style is set for.
However, I would say: first play around with GREP styles in the Find/Change dialog, so you get the GREP. Then transport the GREP into the paragraph style and see if it does its magic as you expect or not.
Copy link to clipboard
Copied
As powerful as GREP is, it can also cause performance issues, especially when applied across an entire document.
Further to @Doc Maik and I agree test the GREPs before applying to styles.
Instead of relying on them throughout your entire document, try using other methods like Nested Styles. Nested Styles can still work with patterns but don’t have the same processing load as GREP. If you can get the same result using Nested Styles, it’s a much lighter option for large files.
Another option is to use Find and Change manually instead of applying GREP styles in real time. This way, you can run GREP searches and apply the formatting only when you need it. A helpful trick is to run all your GREP changes at the end of the document using a GREP manager. This reduces the performance impact by not constantly checking for patterns while you’re working.
A GREP manager is a great tool to streamline this process. It allows you to batch multiple GREP searches and apply all of them in one go. That way, you aren’t constantly running these intensive checks while working, which helps keep things moving smoothly.
However, keep in mind that GREP patterns can sometimes catch things you didn’t intend, especially when dealing with dates or other ambiguous formats. For instance, a pattern that matches “3/25” could be misinterpreted as a fraction, or “26 May 2025” might end up applying a style to a sentence you didn’t want it to. It’s important to refine your GREP patterns to avoid these kinds of errors. For example, you could adjust your search to look for a number followed by a space, ensuring that only real dates get the formatting.
If your document includes different date formats or languages, you’ll need to create separate GREP patterns for each. Dates like “26 May 2025” might appear differently depending on language settings, and regional date styles can vary. So, be ready to adjust your patterns based on these variations to maintain consistency across the document.
Best to use GREP styles thoughtfully. Limit their use to where they’re truly necessary, and consider using Find and Change or a GREP manager to apply them all at once. Be mindful of the impact on performance and always test your patterns to ensure they’re working as expected. If you're dealing with different date formats or languages, fine-tune your GREP searches to avoid errors and inconsistencies.
In short, GREP is a powerful tool, but like any tool, it’s most effective when used with care. By being strategic and testing your patterns regularly, you can automate formatting without running into slowdowns or surprises.
Copy link to clipboard
Copied
Are you typing text from scratch in InDesign - or have you got - more or less "finished" - text from some else?
If you work on Windows - you could use free version of my tool.
You could load all found results of the GREP query - and "accept" them on the case by case basis - but not like when you do F&C that you need to jump from one to the next result - with my tool you get a list of all results and you can tick which one one you want to change - and double-click will get you there instantly:
Copy link to clipboard
Copied
GREP styles almost always come with performance panelties. For formatting dates, numbers, and specific patterns, create a GREP query for each and run them using a script than chains GREP queries (e.g. https://creativepro.com/files/kahrel/indesign/grep_query_runner.html).
An even simpler way is to run a script like the following. On the first line enter the names of your queries, then save the script (as a text file) and run it.
queries = ['dates', 'numbers', 'pattern1', 'pattern2'];
for (i = 0; i < queries.length; i++) {
app.loadFindChangeQuery (queries[i], SearchModes.GREP_SEARCH);
app.documents[0].changeGrep();
}
Copy link to clipboard
Copied
There are kinds of patterns that are known to cause slowdowns, but that's not an InDesign question as such. I don't think I can do the topic justice, to be honest, but it's absolutely worth reading up on inefficient regular expressions. Greedy searches like .* consume more processor cycles than non-greedy searches like .*? for example. You'll find extensive discussions of the topic at places like StackExchange. But there are at least a few InDesign-specific performance issues in its GREP implementation. A positive lookbehind where you're looking for (?<=someThingBefore)mySearch requires the regex engine to run through your search more times than someThingBefore\KmySearch.
But honestly, it's faster to move the processing work elsewhere than it is to produce quality works of efficient regular expression, by the sweat of one's brow, in order to reduce the processing load on InDesign. One clear-cut case where regular expressions are really useful to me is when I have Arabic text with bits of parenthetical English that have to be in another font. If I am going to be expected to drop translated text from a CMS into InDesign and format it rapidly, it makes sense for me to include a GREP Style that applies that Latin-script font to any matches to [A-Za-z]+ but it doesn't make sense if I'm given a 200-page text that has supposedly been finalized and isn't likely to see much revision. It's much faster to just run a Find/Change GREP query that applies a character style to the Latin-script text, either in some text processing tool, before I place the text into InDesign, or immediately upon placing the text. (Thhat is probably the only place where I don't endorse Eugene's post in this thread wholeheartedly; I usually don't wait until the end of the document to run through a list of GREP find/change queries.)
Copy link to clipboard
Copied
Hey @johntom421
I'm jumping in to share my thoughts about your question, and because my favorite solution has only be mentionned, not really explained in depth. Besides, it's a good opportunity to congratulate it's maker again, being @Peter Kahrel (him again, I know, he's everywhere).
I've been there myself, thinking of Grep styles and nested styles as a viable solution to help me out making the layout faster. I'm mainly working on books (game industry, 50+ books a year) that have way over 200 pages, multiple tables, usually 20-50+ paraStyles, 10+ CharStyles …
I would say, Never use those tools too much, or only on very specific and well controlled matter.
Why? because as it's been said, Grep has its own way of always finding something you didn't expect it to find. And a lot happens in 200+ pages. Two "colons" in the same sentence and your "apply Bold charStyle up to it" brings a messy paragraph. And because it's nested, you can't overide it on only one paragraph, (you can break the link to the paraStyle, but if you start doing this, on and on, what's the point of using Grep styles then?)
Moreover, Grep styles can only apply a charStyle on what the grep found. There is no re-ordering of what it has found.
I would only use these tools for :
- dealing with runts (https://luminousworks.com/runts.html)
- dealing with minor formatting (ensure capital letter at the beggining of a paragraph, special combinaison of words with a charStyle -ie Name Of My Company -, mimick Bullets through special Char/Fonts, etc.)
The solution, as I see it best in my workflow, is the Query manager by Peter Kahrel. There are other solutions that do almost the same, but they are not free and not even better 😕
https://creativepro.com/files/kahrel/indesign/grep_query_manager.html
It's versatile, based on the saved queries from ID, but more importantly, you can save presets, group them in a specific way that makes sense in your workflow.
You could use scripts, but Grep queries are easy to use and the Query manager is helping us maximizing their potential.
My two cents ^^
Copy link to clipboard
Copied
[...] but they are not free and not even better 😕 [...]
By @Fred.L
The last part is not true 😉
Peter's script is universal - in terms of working on both Mac and PC - and is free.
But my tool - not free and only available for Windows - let you see what will be changed - and you can decide on case-by-case - browsing list of found results.
You can get results from the whole document - but then limit to specific "locations", specific formatting.
And then you can save the whole process and run it again on another document - with just one click.
And the same Task can be either run on a selected TextFrame, parent Story, whole document - or multiple open documents - or you can process whole server full of documents.
With automatic PDF generation and/or reporting.