Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Jan 2006
    Location
    Oslo, Norway
    Posts
    86
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Get regex matches

    I got a text: $text = "Blah... user1@domain1.com ...blah.... user2@domain2.com ...";

    How do I get hold of the e-mail addresses: user1@domain1.com, user2@domain2.com, ... using regex? How to do it with php?

    UPDATE:
    Would this be an smart way to do it?
    PHP Code:
    preg_match_all("/(\w|\.)*@\w*\.\w*/"$text$match); 
    $match contains all matches, all e-mail addresses in $text. (I also want to match e-mail addresses like user1.sub@domain1.com.)

    Thanks for any suggestions!
    Last edited by jskaar; 06-23-2006 at 01:20 AM.
    DrÝmmejenta: Kristen jente som progger Python!

  • #2
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    /(([_A-Za-z0-9-]+)(\\.[_A-Za-z0-9-]+)*@([A-Za-z0-9-]+)(\\.[A-Za-z0-9-]+)*)/iex

  • #3
    New Coder
    Join Date
    Jan 2006
    Location
    Oslo, Norway
    Posts
    86
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for replying! In danger of beeing stupid: What does the e and x stands for?
    DrÝmmejenta: Kristen jente som progger Python!

  • #4
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    well i and e stand for across lines and case insensitive but dont know about the other one (not my regex)

  • #5
    fci
    fci is offline
    Senior Coder
    Join Date
    Aug 2004
    Location
    Twin Cities
    Posts
    1,345
    Thanks
    0
    Thanked 0 Times in 0 Posts
    refer to
    http://us2.php.net/manual/en/referen....modifiers.php
    i = case insensitive
    e = this will do an eval if you embed php code in it
    x = whitespace characters are ignored in the regex pattern

    the pattern really only needs the i though.

  • #6
    New Coder
    Join Date
    Jan 2006
    Location
    Oslo, Norway
    Posts
    86
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you! I'm starting to figure out this regex thing now... Baby steps, of course, but very useful to learn!
    DrÝmmejenta: Kristen jente som progger Python!


  •  

    Posting Permissions

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