Replacing Using Location Markers

It is easy to insert text before or after a certain character. For example, to insert a tab after a bullet, simply replace each bullet with itself and a tab: find ~8, replace wit~8\t. This approach works both in the Text and the GREP tabs of the Find/ Change dialog and is entirely straightforward. But what if you want to insert text at the beginning or end of a word, paragraph, or story? We saw earlier that location markers match a position, not a character—so what does this mean when you replace things? After all, you can’t replace the start of a story or a word. It seems obvious that these location markers cannot be replaced, but you can use them to find something and ignore them for the replacement. For example, to replace all numbers in a non-automatically numbered list with a bullet, you could use these expressions:

Find what:

^\d+\.?

Change to:

~8

The search expression paraphrases as “Find beginning of paragraph followed by one or more digits, perhaps followed by a dot.” ^, the beginning-of-paragraph marker, is used for the search, but for the replacement it has no meaning. This replacement works because apart from the location marker there is some text that GREP can work with.

All this means that location markers can be used to insert something at a location, but since the location marker is not a character, you need some kind of character to get a handle on the position right before or after the location marker. Another example will ...

Get GREP in InDesign now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.