Select Edit > Find/Change, and select the GREP tab.
- InDesign User Guide
- Get to know InDesign
- Introduction to InDesign
- Workspace
- Generative AI
- Introduction to InDesign
- Create and layout documents
- Documents and pages
- Create documents
- Work with parent pages
- Work with document pages
- Set page size, margins, and bleed
- Work with files and templates
- Convert PDFs to InDesign files in InDesign (Beta)
- Create book files
- Add basic page numbering
- Number pages, chapters, and sections
- Convert QuarkXPress and PageMaker documents
- Share content
- Understand a basic managed-file workflow
- Save documents
- Grids
- Layout aids
- Documents and pages
- Add content
- Text
- Add text to frames
- Threading text
- South-East Asian Scripts
- Arabic and Hebrew features in InDesign
- Create type on a path
- Bullets and numbering
- Glyphs and special characters
- Text composition
- Text variables
- Generate QR codes
- Edit text
- Align text
- Wrap text around objects
- Anchored objects
- Linked content
- Format paragraphs
- Format characters
- Typography
- Format text
- Review text
- Spell check and language dictionaries
- Add references
- Styles
- Tables
- Interactivity
- Graphics
- Color and transparency
- Text
- Find and replace
- Share
- Publish
- Place, export, and publish
- Printing
- Extend InDesign
- Automation
- Troubleshooting
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
-
-
In Find what, follow any of these options to construct a GREP expression:
Construct a GREP expression and enter it.
Select the Special characters for search icon to set your search criteria.
-
Type or paste the replacement text in Change to.
เคล็ดลับ:You can now replace any found text with a specific text case by selecting the Special characters for replace icon > Case Modifiers.
-
Select Find Next.
Select Change, Change All, or Change/Find to replace text and continue searching.
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:
-
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.
-
In the Change to section, select Special characters for replace icon > Found > Found Text.
You can view $0 in the Change to field.
-
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.
-
Select Specify attributes to replace icon in the Change Format section and the formatting.
-
Select Find Next.
Select Change, Change All, or Change/Find to replace text and continue searching.
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 |
\$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.
A 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
-
Select Edit > Find/Change.
-
Select a query from the Query list.
-
Specify a range to search on the Search menu. You can’t save the search range with the query.
-
Select Find Next.
Select Change, Change 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:
-
Select Edit > Find/Change.
-
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.
-
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.
-
Select Edit > Find/Change.
-
Select Text, GREP, or a different tab to undertake the search you want.
-
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.
-
Define the Find what and Change to fields. (See Metacharacters for searching and Search using GREP expressions.)
-
Select the Save Query icon and enter a name for the query.
Delete queries
-
Select Edit > Find/Change.
-
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?
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.