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
- Select the files you want to search through in the File Selector.
- Start with a fresh action.
- Leave the action type as “simple search”. Leave the search type as “regular expression”.
- 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.
- 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:
- 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.
- Select “matches with context” from the “display files and matches” list. This will affect the way the details are displayed in the next step.
- 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.
- 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.
- 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.
- Select the files you want to search through in the File Selector.
- Start with a fresh action.
- Set the action type to “collect data”.
- Turn on “group identical matches”.
- Then turn on the newly revealed option “group results for all files”.
- Leave the search type as “regular expression” and make sure to leave “case sensitive search” off.
- Enter the regular expression \b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b into the Search box.
- Select “save results into a single file” in the target file creation list.
- Click the ellipsis (...) button next to “target file location”, and select the file you want to save the results into.
- 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.
- 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.