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, …
First step is to open the Replace option, Search => Replace or Ctrl+H
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
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 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
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.
Thank you, author, was very useful for me