This writing will be updated with GREP expressions for use in InDesign that I find useful.

First things first: cascading your GREP work.

If you have something that needs to be in all of your paragraph styles, like adjusting InDesign’s hyphenation rules to something that’s not quite so awful or one of the GREP searches on this page, you’ll want to have your paragraph styles based on an existing paragraph style. The best practice is to create a paragraph style based on [Basic Paragraph]. I’ve been creating one simply called basic. To this new paragraph style, I load in all my defaults for the document — the typeface, sizing, leading and all that for the basic copy paragraph style; any GREP queries like applying a character style to the book title; and setting hyphenation and justification settings to what I prefer. All of my other paragraph styles are going to point back to this basic paragraph style.

You’ll want to do this to a new paragraph style because you really want to leave [Basic Paragraph] alone. If you wind up copying and pasting text from a document to another — or hand off your document to someone else — that [Basic Paragraph] definition you’ve created can be overwritten by the newer document’s [Basic Paragraph] definitions. There’s more about that in this article at InDesignSecrets.

So you want to have that newly-created basic paragraph style refer to [Basic Paragraph] and have all other styles be based on basic, or styles whose “based on” trail can be traced back to basic.

For instance, I’ve got five paragraph styles for numbered lists: a numbered list style for items 2 onward (no leading between list item paragraphs); a numbered list, first style for the first item in the list (this has leading above the list item paragraph); a numbered list, last style for the last item in the list (which inserts leading only after the list item paragraph); numbered list, addl, (which has no leading before or after, but has indenting on left and right sides to fit the paragraph in the list’s margins, plus a first line indent so this reads as an additional paragraph that is part of a list item); and, in case the last list item has an additional paragraph, numbered list, addl, last which would have everything numbered list, addl has, plus some leading below the paragraph to separate the list from any other following content. Whew!

So, numbered list, addl, last is based on numbered list, addl, which is based on numbered list… which is based off of bulleted list (which has a whole ‘nother four bullet lists based off of that), which is based off of basic copy (used for the majority of the book’s text), which is then based on basic. Or in other words: basic > basic copy > bulleted list > numbered list > numbered list, addl > numbered list, addl, last. If I make a change to basic, that change cascades all the way down to numbered list, addl, last.

Change all spaces before numbers to non-breaking spaces.

(courtesy Adam Jury)

Search for \s(/d) replace with ~S$1

What this does: This searches for any digit (/d) with a space before it, then replaces the digit with a non-breaking space and the digit. Those parentheses create a backreference; the $1 in the replace string looks in the search string for whatever is in the parenthesis and places it there.

Apply a character style to specific lines of text.

In GREP Styles, search for the actual string of characters, separated by | symbols. Optional items are placed in parenthesis and are followed with a ?.

For example, if I want to apply a character style to every reference of Star Trek’s Enterprise that makes it bold and italic, I’d search for (USS\s)?Enterprise and apply the bold italic character style.

What that example does: This searches for the word strings “Enterprise” and “USS Enterprise” and applies the character style to either of those. The (USS\s)? part searches for the text string “USS” followed by a space, zero or one times. So this will catch USS Enterprise and Enterprise, but not U.S.S. Enterprise.

If I have a statblock that has lines beginning with Armor Class, Hit Points, and Speed, and I want to have those appear as green and in all caps, I’d search for Armor Class|Hit Points|Speed and apply a statblock inline header character style.

What this example does: The | symbol is “or”, so when this comes across “Armor Class” or “Hit Points” or “Speed”, InDesign will apply that character style. However, this will capture all instances of the string “Hit Points” (with a capital H and P). You can make sure this only is applied to the start of any line if you have this as ^(Armor Class|Hit Points|Speed). The ^ character is a location character for the start of the paragraph.

Get rid of orphans.

In GREP Styles, search for \s(?=\w+[[:punct:]]*\s$) and apply the no break character style. The only thing defined in that character style is in the Basic Character Formats view, No Break is checked.

What this does: This searches for any space that is followed by a word and any number of punctuation marks and an optional space at the end of a paragraph. It then places the no break character style on the space character before that last word. In the previous paragraph, this would find ” checked.” and tell InDesign to keep “is checked.” together on the same line. If that last word would be placed as an orphan at the end of the paragraph, it places “is checked.” on that line, avoiding the orphan.


This writing was generously supported by my patrons. You can motivate me to create more writings about layout, game design, and layout in games by becoming a patron. Find out more about my writing goals (plus my secret goal) on this site’s Patreon page.

Leave a Reply

Your email address will not be published.