User Guide Cancel

Find and replace using GREP expressions and queries

  1. InDesign User Guide
  2. Get to know InDesign
    1. Introduction to InDesign
      1. What's New in InDesign
      2. System requirements
      3. Common questions
      4. Use Creative Cloud libraries
    2. Workspace
      1. Workspace basics
      2. Contextual task bar
      3. Customize your workspace in InDesign
      4. Toolbox
      5. Set preferences
      6. Properties panel
      7. Touch workspace
      8. Default keyboard shortcuts
      9. Undo edits and manage History panel
      10. Document recovery and undo
    3. Generative AI (Not available in mainland China)
      1. Text to Image
      2. Generative Expand
      3. Generate Effect in InDesign (Beta)
      4. Generative AI FAQ
  3. Create and layout documents
    1. Documents and pages
      1. Create documents
      2. Work with parent pages
      3. Work with document pages
      4. Set page size, margins, and bleed
      5. Work with files and templates
      6. Convert PDFs to InDesign files in InDesign (Beta)
      7. Create book files
      8. Add basic page numbering
      9. Number pages, chapters, and sections
      10. Convert QuarkXPress and PageMaker documents
      11. Share content
      12. Understand a basic managed-file workflow
      13. Save documents
    2. Grids
      1. Grids
      2. Format grids
    3. Layout aids
      1. Rulers
      2. Align and distribute objects using rulers
      3. Measure objects using the Measure tool
  4. Add content
    1. Text
      1. Add text to frames
      2. Threading text
      3. South-East Asian Scripts
      4. Arabic and Hebrew features in InDesign
      5. Create type on a path
      6. Bullets and numbering
      7. Insert MathML to create math expressions
      8. Glyphs and special characters
      9. Text composition
      10. Text variables
      11. Generate QR codes
      12. Edit text
      13. Align text
      14. Wrap text around objects
      15. Anchored objects
      16. Linked content
      17. Format paragraphs
      18. Format characters
    2. Typography
      1. Using fonts in InDesign
      2. Kerning and tracking
      3. Scale and skew type
      4. Apply color effects to type
    3. Format text
      1. Format text
      2. Auto Style text
      3. Work with Style Packs
      4. Tabs and indents
    4. Review text
      1. Track and review changes
      2. Add editorial notes in InDesign
      3. Import PDF comments
    5. Spell check and language dictionaries
      1. Check spelling, autocorrect, and dynamic spelling
      2. Create, add, and manage dictionaries and words
      3. Change dictionary preferences
      4. Duden dictionary
    6. Add references
      1. Create a table of contents
      2. Footnotes
      3. Create an index
      4. Endnotes
      5. Captions
    7. Styles
      1. Paragraph and character styles
      2. Map, export, and manage styles
      3. Object styles
      4. Drop caps and nested styles
      5. Work with styles
      6. Leading
    8. Tables
      1. Format tables
      2. Create tables
      3. Table and Cell styles
      4. Select and edit tables
      5. Table strokes and fills
    9. Interactivity
      1. Hyperlinks
      2. Dynamic PDF documents
      3. Bookmarks
      4. Buttons
      5. Forms
      6. Animation
      7. Cross-references
      8. Structure PDFs
      9. Page transitions
      10. Movies and sounds
    10. Graphics
      1. Understand paths and shapes
      2. Draw with the Pencil tool
      3. Draw with the Pen tool
      4. Apply line (stroke) settings 
      5. Compound paths and shapes
      6. Edit paths
      7. Clipping paths
      8. Change corner appearance
      9. Frames and objects
      10. Align and distribute objects
      11. Linked and embedded graphics
      12. Integrate AEM assets
    11. Color and transparency
      1. Apply color
      2. Use colors from imported graphics
      3. Work with swatches
      4. Mix inks
      5. Tints
      6. Understand spot and process colors
      7. Blend colors
      8. Gradients
      9. Flatten transparent artwork
      10. Add transparency effects
  5. Find and replace
    1. Find and replace text
    2. Find and replace fonts
    3. Find and replace glyphs
    4. Find and replace using GREP expressions and queries
    5. Find and replace objects
    6. Find and replace colors
    7. Search options to find and replace
  6. Share
    1. Save and access cloud documents
    2. Organize, manage, and share cloud documents
    3. View and manage versions in cloud documents
    4. Common questions about InDesign cloud documents
    5. InCopy on the web (Beta)
    6. Share and collaborate        
    7. Share for Review
    8. Review a shared InDesign document
    9. Manage feedback
    10. Invite to edit
  7. Export, import, and publish
    1. Place, export, and publish
      1. Publish online
      2. Publish online dashboard
      3. Copy, insert graphics
      4. Export to Adobe Express
      5. Export content for EPUB
      6. Adobe PDF options
      7. Export to HTML5
      8. Export content to HTML (Legacy)
      9. Export to Adobe PDF
      10. Export to JPEG or PNG format
      11. Import SVG files
      12. Supported File Formats
      13. Export and import User Settings
    2. Printing
      1. Print booklets
      2. Printer's marks and bleeds
      3. Print documents
      4. Inks, separation, and screen frequency
      5. Overprinting
      6. Create PostScript and EPS files
      7. Preflight files before handoff
      8. Print thumbnails and oversized documents
      9. Prepare PDFs for service providers
      10. Prepare to print separations
  8. Extend InDesign
    1. Automation
      1. Data merge
      2. Plug-ins
      3. Capture extension in InDesign
      4. Scripting
  9. Troubleshooting
    1. Fixed issues
    2. Known issues
    3. Crash on launch
    4. Preference folder read-only issue
    5. Troubleshoot file issues
    6. Unable to export InDesign file to PDF
    7. InDesign document recovery

Learn to create GREP expressions and queries to find and replace alphanumeric strings and patterns.

With GREP expressions, you can find and replace alphanumeric strings and patterns in long or multiple open documents. You can also save frequently used search criteria as queries to save time.

Search using GREP expressions

  1. Select Edit > Find/Change, and select the GREP tab.

  2. In Find what, follow any of these options to construct a GREP expression:

  3. Type or paste the replacement text in Change to.

    Tip:

    You can now replace any found text with a specific text case by selecting the Special characters for replace   icon > Case Modifiers.

    Screenshot of the Find/Change panel with the GREP tab open and Case Modifiers highlighted.
    Select any case modifier to change the text case of found text.

  4. Select Find Next.

    Select Change, Change All, or Change/Find to replace text and continue searching.

Construct a GREP expression

Open a document or multiple documents to find and replace text using GREP expressions.

Example: Find text within quotation marks and change the formatting

Follow these steps to find text within quotation marks and change its formatting:

  1. Type (“)(\w+)(“)in the Find what field.

    This expression contains three groupings, as indicated by the parentheses.

    The first and third groupings search for any quotation mark, and the second grouping searches for one or more word characters.

  2. In the Change to section, select Special characters for replace   icon > Found > Found Text.

    You can view $0 in the Change to field.

  3. Type any of the following in the Change to field to change the required grouping:

    $0 – to change all groupings

    $1 – to change the first grouping

    $2 – to change the second grouping and so on.

  4. Select Specify attributes to replace   icon in the Change Format section and the formatting.

  5. Select Find Next.

    Select Change, Change All, or Change/Find to replace text and continue searching.

Screenshot of the Find/Change panel with the example to find text within double quiotes

A. Find what B. Change to C. Find Format D. Change Format 

Additional GREP examples

Find criteria

Find criteria

GREP Expression

Example

Class of characters

[]

Type the following to find a, b, or c:

 

[abc]

Negative lookahead

(?!pattern)

Use this to avoid a certain pattern from your search. For example, to avoid finding InDesign CS versions from a list of InDesign versions, type:

 

InDesign (?!CS.*?)

Positive lookahead

(?=pattern)

Use this to find a certain pattern. For example, to find InDesign CS versions ONLY from a list of InDesign versions, type:

 

InDesign (?=CS.*?)

Case-insensitive on

(?i)

Use this to find text irrespective of the typing case. For example, if you want to find Apple in any case (apple, APPLE, and so on), type the following:

 

(?i)apple

Case-insensitive off

(?-i)

Use this to find Case-sensitive text. For example, if you want to find Apple ONLY (not apple, APPLE, and so on), type the following:

 

(?-i)apple

Find a character or word a certain number of times

{ }

Type any of the following to find the repeat number of a character or word:

 

b{3} - matches exactly 3 times

b(3,} - matches at least 3 or more times

b{3,}? - matches ONLY 3 times

b{2,3} - matches at least 2 times and not more than 3

Find and change criteria

Find criteria

Find expression

Find result

Change expression

Change result

Find two words with space in between and interchange their position or add anything in between or at the end.

(\w+)\s(\w+)

Adobe InDesign

$1 $2

$2 $1

$1, $2(™)

$1 $2 - Adobe InDesign

$2 $1 - InDesign Adobe

$1, $2(™) - Adobe, Indesign(™)

Change the case of the first letter in a group

(\w+)\s(\w+)

Adobe InDesign

\l

\u

\u$1 $2

\u$1 \u$2

\l\l\u$1 $2

\u$2, \u$1

\u$1 $2 - Adobe indesign

\u$1 \u$2 - Adobe Indesign

\l\l\u$1 $2 - aDOBE INDESIGN

\u$2, \u$1 - Indesign, Adobe

Change the case of all letters in a group

(\w+)\s(\w+)

Adobe InDesign

\L

\U

\U$1 $2

\U$1 \U$2

\U$1 \u$2

\U$1 $2 - ADOBE indesign

\U$1 \U$2 - ADOBE INDESIGN

\U$1 \u$2 - ADOBE Indesign

Note:

\$1 $2 - Adding back slash '\' will act as escape character.

\\u $1 \u$2 - Adding 2 backslash '\' will output single slash.  and can be used to output escape characters in output.

\u$1 \\n \u$2 - "\n" is passed to output, results in new line.

Find and replace items using queries

query is a defined find-and-change operation. InDesign offers several preset queries for changing punctuation formats and other useful actions, such as changing telephone number formats. By saving a query you constructed, you can rerun it and share it with others.

To modify your text, objects, and glyphs, you have the option to either use an existing query or create a new one.

Search using queries

  1. Select Edit > Find/Change.

  2. Select a query from the Query list.

  3. Specify a range to search on the Search menu. You can’t save the search range with the query.

  4. Select Find Next.

    Select ChangeChange All, or Change/Find to replace text and continue searching.

After you select a search query in the Find/Change dialog, you can adjust the settings to fine-tune your search.

Example query: Phone number conversion

Follow along to convert the Phone number format with an in-built query:

  1. Select Edit > Find/Change.

  2. Select Phone Number Conversion (dot format) from the query list. You can see the following in the Find what field:

    \(?(\d\d\d)\)?[-. ]?(\d\d\d)[-. ]?(\d\d\d\d)

    Phone numbers in the United States can appear in various formats, such as 206-555-3982, (206) 555-3982, 206.555.3982, and 206 555 3982. This string looks for any of these variations.

  3. You can edit the grouping references in the Change to field to suit your needs. For example, you could use these expressions:

    206.555.3982 = $1.$2.$3

    206-555-3982 = $1-$2-$3

    (206) 555-3982 = ($1) $2-$3

    206 555 3982 = $1 $2 $3

Save queries

You can save a query in the Find/Change dialog to rerun it or share it with others. You can view the saved queries under the Query list of the Find/Change dialog.

  1. Select Edit > Find/Change.

  2. Select TextGREP, or a different tab to undertake the search you want.

  3. Select the Include Locked Layers and Locked Objects (Find Only)   icon, Include Locked Stories (Find Only)   icon, Include Footnotes   icon, etc., and you can save these along with the query. However, you can’t save the search range.

  4. Define the Find what and Change to fields. (See Metacharacters for searching and Search using GREP expressions.)

  5. Select the Save Query  icon and enter a name for the query.

Delete queries

  1. Select Edit > Find/Change.

  2. Select a query from the list and then select the Delete Query  icon.

Load queries

Customized queries are stored as XML files. The names of customized queries appear in the Query list in the Find/Change dialog.

macOS

Users\[username]\Library\Preferences\Adobe InDesign\[Version]\[Language]\Find-Change Queries\[query type]

Windows XP

Documents and Settings\[username]\Application Data\Adobe\InDesign\[Version]\[Language]\Find-Change Queries\[query type]

Windows Vista and Windows 7

Users\[username]\AppData\Roaming\Adobe\InDesign\[Version]\[Language]\Find-Change Queries\[query type]

More like this

Have a question or an idea?

Ask the Community

If you have a question to ask or an idea to share, come and participate in Adobe InDesign Community. We would love to hear from you and see your creations.

 Adobe

Get help faster and easier

New user?