#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    1
    Rep Power
    0

    RegEx with exceptions


    I am totaly new to RegEx, but I need to extract emails with RegEx from text file

    Some difficulties:

    1. “@”symbol has been substituted for “ at ”,"AT" or "(at)"

    2. I do not need any email with domain "myoldcompany"
    I found that with these I can found any emails:
    "^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$"
    How to do the following?



    Thanks for any help.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Location
    Paris area, France
    Posts
    842
    Rep Power
    496
    My understanding is that you are looking for email addresses.

    Your regex will probably match a majority of email addresses, but will also probably miss many, as email addresses can be much more complicated that what you seem to think (check RFC 2822).

    I would suggest that you use the following module: Regexp::Common::Email::Address.

    A couple of years ago, I had to develop a program for validating email addresses where I could not rely on this module (because the validation rules imposed by the client were too specific in the context), I can tell you that you can quickly get into headaches. Use that module if you can.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Apr 2009
    Posts
    1,947
    Rep Power
    1225
    Regexp::Common::Email::Address doesn't appear to be maintained any longer. At least no updates since Jan 2005.

    Another option would be Email::Addrress which is currently being maintained.

IMN logo majestic logo threadwatch logo seochat tools logo