Removing Everything But Email Address

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, MudGuard

Post Reply
bad959fl
Posts: 21
Joined: Wed Jun 15, 2005 11:32 pm

Removing Everything But Email Address

Post by bad959fl »

Hello Everyone.

I need to figure out how to remove everything from a file while keeping only the email addresses. For example, my original file looks like this:

----------------------
test test test email@email.com blah blah
blah blah blah blah blah blah blah blah
blah blah blah blah test@test.com blah blah blah blah
----------------------

The end result needs to filter everything but the email addresses, like this:

----------------------
email@email.com
test@test.com
----------------------

What is the best way to do this?

Thanks!
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

Here's one way:

First, remove all lines not containing an email address. If it happens that they are the lines not containing an '@' sign then this will do it:
Find what: ^[^@]*\n
Replace with: [nothing]

[X] Regular expression
In the general case, matching all and only email addresses in all their different forms is very hard. But if yours are all of simple form in your example, and if there's only one email address on any one line, this might do it:
Find what: (^|.*[^a-z0-9_.])([a-z0-9_.]+@[a-z0-9_]+(\.[a-z0-9_]+){1,3}).*
Replace with: \2

[X] Regular expression
This assumes you are using Posix regular expression syntax:
Configuration | Preferences | Editor

[X] Use POSIX regular expression syntax
Post Reply