Lawler, Brian, reports on how to put last names first

The original of this post appeared on What They Think in June, 2010. It was brought up to date today, August 21, 2011.

In a recent blog I introduced the idea of GREP styles in Adobe InDesign; that’s a really great feature for the occasional job where you want to format text as it is placed or as it is typed. It can save time in print production.

Today’s example is more common; I use it about once a week. I find I have a list of names (I am a teacher) that is in the wrong name order, either last-name first or the opposite. No matter what, it always seems to be in the wrong order.

So, I use GREP in InDesign to reverse the order. For simple lists (middle names add complexity, so I’ll discuss this later) it’s just a matter of reversing the order of the two words on each line.

My challenge here is to take a last-name-first list, shown in its original form (PDF) above, and reverse it (while shedding some extraneous data in the process). It’s surprisingly simple using GREP. Step one is to copy the text from Adobe Acrobat Professional, and paste it onto a page in InDesign. The context is unimportant. Following is the same material in InDesign:

To make the change, I use the Find-and-Replace pane in InDesign, with GREP selected from the tabs there. The search string in GREP is:

(\d+ )(.+), (\u\l+) (.+)~b

Following is the explanation of how this works:

The selections are automatically assigned to variables as shown. Once the selections are done, I reverse them in the Replace string by putting $3 before $2, separated by a space, and finish with a carriage return. This plays the data back in the opposite order. The remaining elements, stored in $1 and $4, are ignored and discarded.

Above is the functional GREP search and replace pane.

It’s delightfully easy, and it takes almost one second to complete, putting not a moment of wasted time on the clock.

The thing I like most about GREP searches, when they are needed, is how much time they save. Though the seemingly cryptic code can be intimidating, they are easy to build with the pull-down menus for the search and replace functions.

An added benefit of the GREP search pane in InDesign is that it allows you to store your successful search strings, so that you don’t have to puzzle this out more than once after you get it working.


About Brian Lawler

Brian Lawler is an Emeritus Professor of Graphic Communication at California Polytechnic State University, San Luis Obispo and was a Guest Professor at Hochschule München from September, 2021 to September, 2022. He writes about graphic arts processes and technologies for various industry publications, and on his blog, The Blognosticator.
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.