Chapter 1. Introduction

InDesign's Find/Change dialog lets you use four wildcards to search patterns in texts. For instance, using the wildcard ^$ (and setting whole-word-only search), you can use the search pattern r^$^$d to search all four-letter words that start with "r" and end in "d." You can't specify certain groups of letters, though, such as vowels or consonants, to formulate a search pattern like "find all four-letter words beginning with 'r,', followed by a vowel, then a consonant, ending in 'd'." And you can't use wildcards to change text: they are for searching only. Thus, you can't search, say, Diagram ^9 and replace that with Figure ^9 in an attempt to replace the word Diagram with Figure when Diagram is followed by a digit. Nor is it possible to formulate repetitive search patterns—for example, to search for any series of digits, in other words, a search pattern that says in effect, "find all numbers." Instead, you have to search for one-digit numbers, then for two-digit numbers, followed by numbers consisting of three digits, etc. The three other wildcards in InDesign are ^9 (any digit), ^? (any character), and ^w (any white space); they share the restrictions of the digit wildcard.

These wildcards can be used in scripts as well, but they suffer from the same limitations that are encountered in the user interface: pattern-matching is on a strict character-by-character basis, and you can't use wildcards to replace anything.

Fortunately, regular expressions offer ...

Get Automating InDesign with Regular Expressions now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.