<Original message>
From: Jack Dempsey <[EMAIL PROTECTED]>
Date: Mon, Sep 17, 2001 at 09:41:07PM -0400
Message-ID: <[EMAIL PROTECTED]>
Subject: RE: [PHP] real simple regex

> you actually don't need regex...
> if you take a few minutes you can do it all with strpos and substr, adn
> it'll be faster than regex.....

</Original message>

<Reply>

Not realy the very best solution to use strpos and substr. You'll
have to loop through the "From-string" and look for the next address
each time. You can have more than one address in the From-field! And
then again... what would you do with addresses that are not between
< and >? Eg.: Renze Munnik <[EMAIL PROTECTED]>, [EMAIL PROTECTED]
Using strpos and substr won't realy make you're live any simpler.

I suggest you use something like the following RE:
        $emlchars = "[a-z0-9.-]+";
        $RE = "/($emlchars@$emlchars)/i";

I've put the allowed characters for the email-address in a separate
string in order to make it read easier. You can add all characters
to that string that are also allowed, because I don't believe these
are the only allowed characters in an email-address.
How to use? See the following example code:

--- PHP Code ---
<PRE>
<?php

$from = "* R&zE: <[EMAIL PROTECTED]>,
         [EMAIL PROTECTED],
         Mr Nobody <[EMAIL PROTECTED]>";
$emlchars = "[a-z0-9.-]+";
$RE = "/($emlchars@$emlchars)/i";

if (preg_match_all ($RE, $from, $matches)) {
  print ("<H1>Matched!</H1>\n\n");
  print_r ($matches);
} else {
  print ("<H1>Didn't match!</H1>");
}

?>
</PRE>
--- End of PHP Code ---

</Reply>

-- 

* R&zE:


-- »»»»»»»»»»»»»»»»»»»»»»»»
-- Renze Munnik
-- DataLink BV
--
-- E: [EMAIL PROTECTED]
-- W: +31 23 5326162
-- F: +31 23 5322144
-- M: +31 6 21811143
--
-- Stationsplein 82
-- 2011 LM  HAARLEM
-- Netherlands
--
-- http://www.datalink.nl
-- ««««««««««««««««««««««««

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to