Page 1 of 1

Extracting Email Addresses Only

Posted: Fri Jun 29, 2007 12:07 am
by bad959fl
I just extracted over 10K user accounts from our forum and it ended up in this format:

username user@email.com

How can I extract only the email address from this line? I tried bookmarking "@", but it picked up the username also. Any thoughts?

Posted: Fri Jun 29, 2007 2:07 am
by Bob Hansen
Search for: ^.+[[:blank:]]
Replace with: nothing


Using POSIX and RegEx on

Always have a backup available.

Posted: Fri Jun 29, 2007 2:23 am
by bad959fl
Hi Bob,

Thanks but it seemed to remove all the lines but one. The text file is listed with over 10K lines like this:

-------------------------------------
username1 email@email1.com
username2 email@email2.com
username3 email@email3.com
-------------------------------------

I want it to end up like this:

-------------------------------------
email@email1.com
email@email2.com
email@email3.com
-------------------------------------

Thanks!

Posted: Fri Jun 29, 2007 2:37 am
by Bob Hansen
Just took your last example.
I end up with this:

-------------------------------------
email@email1.com
email@email2.com
email@email3.com
-------------------------------------

Looks the same to me. What am I not seeing?

Posted: Fri Jun 29, 2007 2:45 am
by bad959fl
Turned on POSIX and now it removes everything (reg exp: on). Here are my setting:

Find What: ^.+[[:blank:]]
Replace with: nothing

Posted: Fri Jun 29, 2007 5:43 am
by MudGuard
.+ is greedy, so if there is a blank at the end of the line, it removes all.

use
^[^[:blank:]]+[[:blank:]]
instead, i.e. search for as many non-blanks as possible at the beginning of the line plus one blank after that.


If your user names can contain blanks, it gets more complicated:
^.*[[:blank:]]([^[:blank:]]+@)
replace by \1

Posted: Fri Jun 29, 2007 7:29 pm
by Bob Hansen
Thanks MudGuard for pointing out the invisible spaces at the ends of the line.

I should have thought of that myself even though there was no mention of it in the samples.

Posted: Fri Jun 29, 2007 7:48 pm
by bad959fl
Great, worked perfectly! Thanks guys :)

Posted: Fri Jun 29, 2007 8:03 pm
by bad959fl
Ah, wrote too soon. It seems like there are many entries which still left the username in the line with a space after it. Is there a way to remove all extra spaces only at the end of the line? This way, I can weed them out and do a search for the username spaces after that.

Posted: Fri Jun 29, 2007 9:36 pm
by ben_josephs
Find what: _+$ [Replace the underscore with a space]
Replace with: [nothing]

[X] Regular expression