Find Email Addresses

Searching for email addresses is easy with PowerGREP, and a very good example of the benefit of regular expressions. Instead of searching for a particular email address, with a regular expression you can search for any email address. If you forget somebody's address, simply search your correspondence. Getting a list of address of everybody you've communicated with is just as easy.

Depending on the kinds of files you want to find these email addresses in, you may want to check out these examples first. They elaborate what is summarized as step 1 here.

Finding a Particular, Unspecified Email Address

  1. Select the files you want to search through in the File Selector.
  2. Start with a fresh action.
  3. Leave the action type as "simple search". Leave the search type as "regular expression".
  4. In the search box, enter the regular expression \b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b and make sure to leave "case sensitive search" off.
  5. Click the Preview button to run the action.

When the action completes running, you will get the list of email addresses on the Results panel. If the list is long, you can sort out the addresses as follows:

  1. Select "per unique match" from the "group search matches" list, and click the Update button. Each email address now appears only once in the list.
  2. Select "matches with context" from the "display files and matches" list. This will affect the way the details are displayed in the next step.
  3. Double-click on an email address to see in which files it occurs. The details will appear in the bottom part of the Results panel.
  4. Double-click on an address in the details to open the document it was found in. Check the document to see if it is the address you want.
  5. If not, switch back the Results panel and repeat from step 8.

This action is available in the PowerGREP5.pgl library as "Email: Find email addresses".

How to Get a List of all Email Addresses

When you follow the above steps, you will get a list of all addresses in step 6. If you want to save the results into a file, you can either copy-and-paste the results from step 6 above into a text editor, or you can make PowerGREP do this for you with the steps below.

  1. Select the files you want to search through in the File Selector.
  2. Start with a fresh action.
  3. Set the action type to "collect data".
  4. Turn on "group identical matches".
  5. Then turn on the newly revealed option "group results for all files".
  6. Leave the search type as "regular expression" and make sure to leave "case sensitive search" off.
  7. Enter the regular expression \b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b into the Search box.
  8. Select "save results into a single file" in the target file creation list.
  9. Click the ellipsis (...) button next to "target file location", and select the file you want to save the results into.
  10. If you want a comma-delimited list of addresses for use with email software, set "between collected text" to "text between matches and files". Then type in a comma in the box that appears below the "between collected text" drop-down list.
  11. Click the Collect button to run the action.

This will produce the same results as in step 6 in the first method, with one difference: if you double-click an address in the results, PowerGREP will open the target file in the editor rather than the file the email address was found in.

This action is available in the PowerGREP5.pgl library as "Email: Get a list of all email addresses (one per line)". The comma-delimited variant is available as "Email: Get a list of all email addresses delimited with commas". The actions in the sample library use a more complicated and slightly more accurate regex to find the email addresses. But the basic regex shown above will do the job just fine. The section with regular expression examples in this help file has a detailed discussion about matching email addresses with regular expressions with many more examples.