I received a file containing 100 pages of information in a table. The table needed to be placed into InDesign. No problem…
Well, of course there was one problem. Randomly, the lines began with spaces. Not every line, but most lines. So the left edge of the table looked ragged. So how do you take out random spaces at the beginning of text? In a table? Without doing it manually? (Because I have much better things to do than going through a 100+ page document line-by-line…)
What is GREP?
In InDesign CS3 and CS4, you can choose to do GREP find and change. GREP is a text search function originally written for UNIX. Basically, it lets you look for patterns and allows you to do find and replace based on those patterns.
So back to the random spaces…
What I had was a pattern. Find all spaces at the beginning of the paragraph and replace with nothing. GREP was the perfect solution.
Next to the find and change fields are flyout menus (marked with “@”) that give you shortcuts to all of the variables. For example, go to “Locations>Beginning of a Paragraph” and InDesign inserts a “^” into the field.
So I typed “^ ” (there is a space after the ^) in the “Find what” field – which tells InDesign to find one space at the beginning of any paragraph. I left the “Change to” field blank, clicked “Change All” and several thousand instances were changed instantly. Without having to go through line-by-line…
EDIT: Above, I set up the search with the ^ (to find the beginning of the paragraph) and a space after it. And while it works, a reader pointed out correctly that a better search would have been “^\s+” which would have found one or more spaces at the beginning of a line.
What else can GREP do?
I’ve used GREP to replace dashes or periods at the beginning of lines. And GREP is perfect for standardizing the formatting of a phone number across an entire document. GREP is amazingly powerful and you can build a GREP search for anything with a pattern. I’ve only scratched the surface…
You can save queries to be reused. (Several sample searches – including a phone number formatting query – are already saved as a sample searches in InDesign. It’s located at the top of the dialog box.)
InDesign also lets you apply GREP-based character styles – for example, telling it to find all prices in a document and apply a particular style.
It’s probably not for everyone.
You aren’t going to need GREP find/change unless you are doing some pretty heavy duty, long document work like magazines, catalogs and directories.
I’m pretty sure most InDesign users aren’t doing that kind of work. But if that type of project comes across your desk, keep in mind that GREP might be a great – and time-saving – solution for your project.
Want to learn more about what GREP can do for you? If you do a search for GREP, there are lots of resources out there. Two that I have found helpful:
- A very helpful and well-written PDF from Michael Murphy at The InDesigner. It’s actually about CS3, but it’s very helpful in detailing how to build a GREP search.
- Search using GREP expressions from Adobe’s InDesign help documentation. Provides some great examples of what GREP is capable of doing.