Notepad++ how to extract email addresses from a file

Quick links

How to extract email addresses from text 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.

Notepad++ regex extract text

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

Nnotepad++ regular expression

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 Marktab 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.

Extract emails from text file

To extract emails from a text file, open it using Notepad++ text editor, and apply the instructions above, by using a regular expression, tagging all emails, selecting only the emails, and copying them.

Extract emails from CSV

The email addresses in a CSV, such as a MicrosoftOutlook export, works exactly the same as for a standard text file. Open the CSV file with Notepad++ text editor, distinguish the single email addresses with the process explained above, and copy them.

Notepad++ copy all regex matches

To copy all regex matches, use the Marktab in Notepad++ search window. By putting here the regexp, all results matching the regexp will be marked, and can be selected and copied that way.

Remove duplicates in notepad++

Read more

Similar articles

Comments (5)

Irene Page, 2018-08-19
Simple, clair et bien expliqué, merci beaucoup
Lee Ryan, 2018-08-19
No sabía acerca de estos detalles, por favor haga más
Raymond Mcbride, 2018-08-19
O poveste grozavă, mulțumesc pentru schimbul
Kathryn Baker, 2018-08-19
ที่ทำงานได้ดีสำหรับฉันไม่จำเป็นต้องดูเพิ่มเติมใด ๆ
testkingaws, 2018-11-05
Thank you, author, was very useful for me

Leave a comment