Justtechjobs.com Find a programming school near you






Online Campus Both


php-general | 2001092

Re: [PHP] real simple regex From: * R&zE: (renze <email protected>)
Date: 09/18/01

<Original message>
From: Jack Dempsey <dempsejn <email protected>>
Date: Mon, Sep 17, 2001 at 09:41:07PM -0400
Message-ID: <NEBBKBGAMLPMIDAJEALPIEIMCHAA.dempsejn <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 <renze <email protected>>, someone <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: <renze <email protected>>,
         someone <email protected>,
         Mr Nobody <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: renze <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: php-general-unsubscribe <email protected> For additional commands, e-mail: php-general-help <email protected> To contact the list administrators, e-mail: php-list-admin <email protected>