Publishing Tools

GREP Expressions & InDesign Scripts

A toolbox for editing books in Adobe InDesign. Copy any expression directly into InDesign's Find/Change dialog. When using a replacement value of $1, the expression removes formatting markers so you can then apply styles with a hotkey (e.g., N + H + F1 for italics).

GREP Expressions

1. Find Sentences Not Starting with a CAPITAL

This expression finds sentences that begin with a lowercase letter and end with a period. Great for catching mis-formatted paragraphs.

^[a-z].+?\.

2. Italics in Adobe InDesign

Find text wrapped in underscores or asterisks. When you replace with $1, it removes the markers so you can then apply italics using your hotkey (e.g., N + H + F1).

Find What (underscores):
_([A-Za-z ]+)_
Find What (any content):
_([^_]+)_
Change To:
$1

3. Fixing Wrong Line Breaks

Removes one or more incorrect paragraph breaks that appear before a sentence beginning with a lowercase letter. Collapses the line(s) so the sentence flows correctly.

Find What:
\r+([a-z].+?\.)
Change To:
$1
Change To (with space):
 $1

4. Find Text in Quotes

Finds any text surrounded by standard double quotation marks.

"([^"]+)"

5. Find Text Enclosed in Single Asterisks

Matches text wrapped by a single asterisk on each side — useful for finding bold or emphasis markers.

\*([^*]+)\*

6. Find Text Enclosed in Double Asterisks

Matches text wrapped by double asterisks — the markdown bold syntax.

\*\*([^*]+)\*\*

7. Find Roman Numerals

Locates Roman numeral sequences like chapter numbers or act/scene labels.

\b([IVXLCDM]{2,}|[VXLCDM])\b

8. Google Docs: Proof Dialog Tags

Finds quotation marks that aren't preceded by ] or followed by [, ensuring dialog tags are properly marked.

(?<!] )"(?!\[)(?=\S)

InDesign Scripts

Center Titles Script

Inserts six soft returns before paragraphs with the Title style to help center them on the page.

// Define the paragraph style name
var titleParagraphStyle = "Title";

// Get the active document
var doc = app.activeDocument;

// Loop through all text frames in the document
for (var i = 0; i < doc.textFrames.length; i++) {
    var textFrame = doc.textFrames[i];

    // Loop through all paragraphs in the text frame
    for (var j = 0; j < textFrame.paragraphs.length; j++) {
        var paragraph = textFrame.paragraphs[j];

        // Check if the paragraph has the paragraph style "Title"
        if (paragraph.appliedParagraphStyle.name == titleParagraphStyle) {
            // Insert 6 soft returns before the title
            paragraph.insertionPoints[0].contents = "\n\n\n\n\n\n";
        }
    }
}

alert("Six soft returns added before all paragraphs with the 'Title' style.");

Auto Apply Master Page for Title Paragraph Style

Checks the active document for pages containing text with the Title paragraph style. When found, it applies a designated master page named D-Parent to those pages.

var titleParagraphStyle = "Title";
var dParentMasterPageName = "D-Parent";
var doc = app.activeDocument;

if (!doc.saved) {
    alert("Please save the document before running this script.");
} else {
    var pageCount = 0;

    for (var i = 0; i < doc.pages.length; i++) {
        var page = doc.pages[i];
        var containsTitle = false;
        var textFrames = page.textFrames;

        for (var j = 0; j < textFrames.length; j++) {
            var textFrame = textFrames[j];
            var paragraphs = textFrame.paragraphs;
            for (var k = 0; k < paragraphs.length; k++) {
                if (paragraphs[k].appliedParagraphStyle.name == titleParagraphStyle) {
                    containsTitle = true;
                    break;
                }
            }
            if (containsTitle) break;
        }

        if (containsTitle) {
            pageCount++;
            try {
                var masterPage = doc.masterSpreads.itemByName(dParentMasterPageName);
                if (masterPage.isValid) {
                    page.appliedMaster = masterPage;
                } else {
                    alert("Master page '" + dParentMasterPageName + "' is not valid.");
                }
            } catch (e) {
                alert("Error applying master page: " + e);
            }
        }
    }

    alert("Master page '" + dParentMasterPageName + "' applied to " + pageCount + " page(s).");
}