Jump to content

Regex for extracting e-mail addresses


leuce
 Share

Recommended Posts

I'm not sure of the exact rules, but I think each email address must:

  • Not contain spaces
  • Contain an @
  • Contain a period with an ending (ie: .com, .org, .edu, etc)

So you could use something simple like this:

([^\s]*@[^\s]*\.[^\s]*)

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager
InputBoxes - Simple Input boxes for various variable types

Link to comment
Share on other sites

47 minutes ago, FrancescoDiMuro said:

@leuce

Why don't you show us what you tried?

I could do that, of course, but how would I (or you) know of the regex is any good?  Even if it manages to extract *some* e-mail addresses would not be proof that it is the proper regex for extracting *all* e-mail addresses.  The whole point of using the correct regular expression is to avoid using an expression that works only in test cases.  Are you saying that you'll tell me the correct answer only after I've given you some likely incorrect attempts? :-)

Edited by leuce
Link to comment
Share on other sites

To kill this bird, here's the optimized regex J. Friedl published in his first edition of "Mastering Regular Expressions".  Just like he said: Enjoy!

1350608643_emailregex.thumb.jpg.65d2f7b08541c78a3ec6d61630ef20ed.jpg

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...