How To Extract Email Addresses From Text?

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


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?”.

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, …

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

Nnotepad++ regular expression

Here, in Find what, enter below regular expression.

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

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

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

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

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

In Search => Bookmark, select the Remove Unbookmarked Lines

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

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.

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.

Notepad++ strip HTML tags

To remove the HTML tags in Notepad++ from a text, use below  regular expression   <.*?>|</.*?>, and replace for example with a space. Make sure that the  regular expression   check box in the search form has been selected.

Notepad++ extract URLs

In the replace menu, accessible with shortcut CTRL+H, use the following regexp, with the  regular expression   and dot matches new line checked:

Explore Your Business Potential: Discover Our Range of Transformative Courses Today!

Unveil the power of knowledge with our diverse array of courses, from Operational Procurement in S/4HANA to SEO essentials. Elevate your expertise and drive success in your business ventures.

Get your course

And use this replace string in order to get a list of all URLs extracted in the file:

How to copy marked lines in NotePad++ ?

Marked text in Notepad++ can be copied using a regex search, by using the search > mark menu, selecting bookmark line and clicking mark all.

Then, use the search > bookmark > copy bookmarked lines menu, and the result can be pasted in a new file, containing the copy of marked lines.

How to extract emails from text in a few clicks?

To extract emails from text, simply enter a  regular expression   to find out all the email addresses in a text file, for example an extraction of all your contacts from Microsoft Outlook.

Then, identify the email addresses, and remove the extra lines. Using NotePad++, it can easily be done by following our guide.

extract email address from Notepad++ using regex

How to extract emails from CSV file?

The email addresses in a CSV, such as a MicrosoftOutlook export, works exactly the same as for a standard text file.

To extract emails from CSV file, start by opening the CSV file with Notepad++ text editor, distinguish the single email addresses with the process explained above, and copy them.

To  extract emails from CSV file   follow the following process:

  • Open the CSV file with Notepad++ text editor,
  • Enter  regular expression   matching potential email addresses,
  • Replace them with email and line break,
  • Use a  regular expression   to bookmark effective email addresses,
  • Remove lines unbookmarked that don’t contain email addresses,
  • Get a final list by performing a  remove duplicates   operation that will clean your file and have the emails extracted from your CSV file and ready to export.

Once the  extract emails from CSV file   process has been completed using a regular expression, you will be able to copy them directly from the results.

GMAIL: How to send an email to all contacts?

Using the popular email application GMAIL, it is possible to send an email to all contacts by first extracting the contact list.

To do so, open your Google contacts, and go to the “other contacts” menu, where you’ll find the email addresses of anyone you’ve ever exchanged an email with.

Then, select a contact by clicking on the checkbox next to it – and a new menu will appear, allowing you to select all contacts you want by expanding the blue arrow, and then to export all your GMAIL contacts emails by clicking on the three blue dots on the right, and selecting the email export options to local file that suits your needs: Google CSV, Outlook CSV, or vCard for iOS contacts.

If you have too many contacts to handle in the resulting CSV file, consider splitting your CSV file.

Split your CSV text file with contacts exported from GMAIL

You can also export all contacts directly from this menu by selecting the appropriate option, the all contacts checkbox.

Frequently Asked Questions

How is the email extractor from text files ?
To extract emails from a text file, open it with the Notepad++ text editor and apply the instructions above using a regular expression, marking all emails, selecting only emails, and copying them.

Yoann Bierling
About the author - Yoann Bierling
Yoann Bierling is a Web Publishing & Digital Consulting professional, making a global impact through expertise and innovation in technologies. Passionate about empowering individuals and organizations to thrive in the digital age, he is driven to deliver exceptional results and drive growth through educational content creation.


Explore Your Business Potential: Discover Our Range of Transformative Courses Today!

Unveil the power of knowledge with our diverse array of courses, from Operational Procurement in S/4HANA to SEO essentials. Elevate your expertise and drive success in your business ventures.

Get your course



Comments (4)

 2018-08-19 -  Irene Page
Simple, clear and well explained, thank you very much
 2018-11-05 -  testkingaws
Thank you, author, was very useful for me
 2019-01-15 -  George Mauricio Santana Lima
THIS TUTORIAL IS AMAZING, SUCH AN USEFUL GUIDE! <3
 2019-01-15 -  Kaspars
Thank you! This came handy!

Leave a comment