Swap Names Around with GREP and Find/Change
Joe needs to convert all his captions in the form LastName_FirstName.jpg into "FirstName LastName." It's way easier than you'd think.
Joe wrote:
I have about two hundred text boxes which are captions of student pictures produced by Bob Stucky’s contact sheet script. The captions are actually the file name in this format: LastName_FirstName.jpg. I need to change to FirstName (space) LastName (no file extension).
Sounds like a job for super GREP! Try this: Open the Find/Change dialog box and switch to the GREP tab (this is in CS3 and later). Type this into the Find what field:
^(\w+)_(\w+)\.jpg
Type this into the Change to field:
$2 $1
Now click Change All. That should do it!
Here’s how to decode the grep codes:
- ^ means “beginning of paragraph”
- (\w+) means “remember what the first group of one or more word characters are”
- _ is literal — that is, it’s just looking for an underscore character
- \. means a period/dot (you have to “escape” that character with the backslash before it)
- .jpg is also just literal
- $2 $1 means “take the second word group you found (the stuff in parentheses), then type a space, then type the first word group you found”
There, that wasn’t so hard, was it?
This article was last modified on December 19, 2021
This article was first published on June 5, 2009
Commenting is easier and faster when you're logged in!
Recommended for you
Find More Than One Paragraph with GREP
GREP is, by default, set up to find text inside a paragraph. That is, if you sea...
Getting Rid of Text Size Parentheses
Jesi wrote: ...When I copy and paste the entire ad into a different template and...
InDesign Magazine Issue 76: Publish Anywhere with InDesign to HTML5
We’re happy to announce that InDesign Magazine Issue 76 (August, 2015) is now av...
