Page 1 of 1

Removing Everything But Email Address

Posted: Tue Nov 15, 2005 3:36 pm
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!

Posted: Tue Nov 15, 2005 4:35 pm
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