GREP of the Month: Email Addresses
Learn how to automatically format email addresses when applying a paragraph style.
This article appears in Issue 70 of InDesign Magazine.
InDesign helps you format email addresses when you use the Convert URLs to Hyperlinks command (in the Hyperlinks panel menu). But you have to run this command manually and repeat the process every time you’re handed new text. Instead, why not automate this process using GREP styles?
Knowing what you’re looking for
When you look at the structure of an email address, you’ll see that there are a lot of formations. Here are just a few examples: ba***************@******gn.com ba**********@*******om.au
You might think you need to look for any upper- or lowercase character, digit…or another special character…followed by the “@” symbol…followed by another series of characters…followed by a period…followed by “a few” other characters…Notice how hard this is getting? Let’s change strategies.
Knowing what you’re NOT looking for
One character you know cannot be part of an email address is the regular space character: , in GREP-speak. But instead of looking for , look for \S, because using uppercase tells InDesign to look for everything EXCEPT that character.
Creating your GREP style
Start by editing your paragraph style. Add a new GREP style, and then, for the expression, type \w\S+@\S+\w
\w looks for a “word character,” which is either an uppercase character, a lowercase character, or a digit. This helps avoid issues where an email address is next to a comma, parenthesis, or other characters that can’t be part of the address.
\S+ looks for a series of characters that does not include a space character.
@ looks for the actual @ character.
Commenting is easier and faster when you're logged in!
Recommended for you
Script of the Month: What the GREP?
This month’s script can help you understand and troubleshoot GREP expressions.
GREP of the Month: Horizontal and Vertical Spaces
Erica Gamet offers some easy to remember codes you can use to quickly select any...
Cleaning Up White Space Problems in Word Files
Proven methods for removing messy white space characters that can cause trouble...
