Various

Notepad++ how to extract email addresses from a file

Having a file, for example an extraction from your mailbox, and you want to extract only the email addresses ?

Using Notepad++ and simple regular expression, that’s pretty simple.

See below a full example, or, to summarize, open your file, use below regexp to find email addresses, add line breaks before and after each of them, and then mark the lines containing an email address and delete the unmarked lines.

Pretty straightforward – but see below a full example using this clever regexp from a Stackoverflow.com discussion on “Extract email from text using notepad++ and regexp”, and with further inspiration from a superuser.com discussion “How to delete all lines in Notepad++ except lines containing a word I need?”.
(\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}\b)

Starting with your file – in that example, an extraction of the “TO” addresses of an Outlook 2013 sent emails folder – you might have a lot of strange characters, unnecessary text, email addresses on the same line, …

Notepad++ how to extract email addresses from a file : File containing email addresses and other information
File containing email addresses and other information

First step is to open the Replace option, Search => Replace or Ctrl+H

Notepad++ how to extract email addresses from a file : Search => Replace menu
Search => Replace menu

Here, in Find what, enter below regular expression.
(\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}\b)

In Replace with, enter this to replace each email address by : line break \n + search string $1 + line break \n
\n$1\n

Make sure to check the Regular Expression radio button, and click Replace All

Notepad++ how to extract email addresses from a file : Replace email addresses to add line break before and after each of them
Replace email addresses to add line break before and after each of them

See the result – each email address is now alone on a new line.

Notepad++ how to extract email addresses from a file : File with email addresses separated from the text by line breaks
File with email addresses separated from the text by line breaks

Next step is to identify all these lines containing only a single email address. Open the Mark tab in the Search window. Copy the same regexp as before to identify the email addresses. Make sure the Regular expression is checked, along with the Bookmark line option, and start the marking operation with Mark All

Notepad++ how to extract email addresses from a file : Options to mark lines containing only an email address
Options to mark lines containing only an email address

In the file, all lines containing email addresses are now bookmarked.

Notepad++ how to extract email addresses from a file : Email addresses bookmarked in the file
Email addresses bookmarked in the file

In Search => Bookmark, select the Remove Unbookmarked Lines

Notepad++ how to extract email addresses from a file : Option to delete unbookmarked lines
Option to delete unbookmarked lines

And voilà ! Your file now only contains the email addresses without unnecessary text.

Notepad++ how to extract email addresses from a file : Final file containing only email addresses
Final file containing only email addresses

As a last step, you might want to remove duplicates to have a list of unique email addresses.

Order a list and remove duplicates
Order a list and remove duplicates

Read more about it

Plan your next business trip

[tp_popular_routes_widget destination=MOW responsive=true subid=””]
[tp_popular_routes_widget destination=PAR responsive=true subid=””]
[tp_popular_routes_widget destination=AMS responsive=true subid=””]
Plan your next business trip

One thought on “Notepad++ how to extract email addresses from a file

Comments are closed.