SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: A regex problem

  1. #1
    SitePoint Addict pentium10's Avatar
    Join Date
    Apr 2004
    Location
    Transilvania
    Posts
    208
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    A regex problem

    how to find in a string all email addresses....

    $string = ' "Culture" <Culture@mokus.info>, "Beats & Events GmbH" <nachtweh@cultureclub-hanau.de> ';

    and i want
    Culture@mokus.info
    nachtweh@cultureclub-hanau.de
    Rype :: book, do, charge, collect,
    track time, track expenses and invoice easily on the go.
    Available on Mac, Win, iPhone, WinMobile.
    http://www.rypenow.com

  2. #2
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hopefully this will work
    PHP Code:
        $string ' "Culture" <Culture@mokus.info>, "Beats & Events GmbH" <nachtweh@cultureclub-hanau.de> ';
        if(
    preg_match_all('~<(.*)>~U',$string,$matchArr))
        {
            
    print_r($matchArr);
        } 
    ---------------------------
    Errors = Improved Programming.
    My Site

  3. #3
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I think that the following pattern will match valid email addresses:

    PHP Code:
    $pattern '/[a-z0-9._-]+@([a-z0-9-]+\.)+[a-z]{2,6}/i';
    preg_match_all($pattern$string$match);

    $emails $match[0]; // an array with all the addresses 
    ERIK RIKLUND :: Yes, I've been gone quite a while.

  4. #4
    SitePoint Addict pentium10's Avatar
    Join Date
    Apr 2004
    Location
    Transilvania
    Posts
    208
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks
    Rype :: book, do, charge, collect,
    track time, track expenses and invoice easily on the go.
    Available on Mac, Win, iPhone, WinMobile.
    http://www.rypenow.com


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •