Welcome Guest, Not a member yet? Register   Sign In
Email addresses with a "+" are not parsed correctly
#14

[eluser]sophistry[/eluser]
I trimmed it down. Now, there are fewer faults and it is smaller. I took out the regex description and added a few more test emails. i decided that since ICANN will accept single char domains eventually, that this should too (plus it was too hard to figure out how to exclude them in regex alone). also, like the previous versions, this cannot distinguish between real TLDs and invalid ones.

NOTE: i removed the single-quote and the backtick from the char list because it was messing up the formatting.
Code:
<?php
class Test extends Controller {

    function Test()
    {
        parent::Controller();
    }
        
    function index()
    {
        $strs = array(
                    "back|to=school~w0w.does+this^[email protected]",
                    "back{to}school-does+this^[email protected]",
                    'back{to}school#[email protected]',
                    '[email protected]',
                    '[email protected].',
                    '[email protected]..',
                    '[email protected]',
                    '[email protected]',
                    '[email protected]',
                    '[email protected]',
                    'h#[email protected]',
                    '[email protected]',
                    'h$[email protected]',
                    'h%[email protected]',
                    'h&ampersand;@example.com',
                    'h*[email protected]',
                    '[email protected]',
                    'h/[email protected]',
                    "h'[email protected]",
                    '[email protected]',
                    '[email protected]',
                    'h^[email protected]',
                    '[email protected]',
                    'h`[email protected]',
                    'h{[email protected]',
                    'h}[email protected]',
                    'h|[email protected]',
                    '[email protected]',
                    'h.r@[email protected]',
                    '[email protected]@many-at-signs.com',
                    '[email protected]@many-at-signs.com',
                    '[email protected]',
                    '[email protected].',
                    '[email protected]',
                    '[email protected]',
                    '[email protected]',
                    '[email protected]',
                    '[email protected]',
                    '[email protected]',
                    '[email protected]',
                    '[email protected]',
                    '[email protected]',
                    '[email protected]',
                    '[email protected]',
                    '[email protected]',
                    '[email protected]',
                    '[email protected]',
                    '[email protected]',
                    '[email protected]',
                    '[email protected]',
                    '[email protected]',
                    '[email protected]',
                    '[email protected]',
                    '[email protected]',
                    '[email protected]',
                    '[email protected]',
                    '[email protected]',
                    '[email protected]',
                    'no-at-signs.com',
                    '[email protected]',
                    '[email protected]',
                    '[email protected]',
                        );
        // NOTE: add the escaped single-quote and the backtick back in for completeness
        $chars_not_dot = '-a-z0-9#!$%&*+/=?^_{}|~';
        
        $tlds = $this->_get_tld_regex();
        
        $email_detector_regex_NEW_array = array();
        $email_detector_regex_OLD_array = array();
        foreach ($strs as $str)
        {
            preg_match_all(";([$chars_not_dot](?:[$chars_not_dot]|[.](?![.]))*)(?<![.])@((?:[[:alnum:]])(?:[[:alnum:]]|[-.](?![-.]))+(?<=[.])(?:[[:alnum:]]){2,});i", $str, $matches);
            //$this->_p($str);
            //$this->_p($matches);
            $email_detector_regex_NEW_array[]=array($str,@$matches[0][0],@$matches[1][0],@$matches[2][0]);
        }
        
        foreach ($strs as $str)
        {
            // the original auto_link email matcher
            preg_match_all("/([a-zA-Z0-9_\.\-]+)@([a-zA-Z0-9\-]+)\.([a-zA-Z0-9\-\.]*)/i", $str, $matches);
            //$this->_p($str);
            //$this->_p($matches);
            $email_detector_regex_OLD_array[]=array($str,@$matches[0][0],@$matches[1][0],@$matches[2][0]);

        }
        //$this->_p($email_detector_regex_NEW_array);

        $this->load->library('table');
        $this->table->set_heading('String In', 'Full pattern', 'mailbox', 'domain');
        echo '<hr>NEW regex';
        echo $this->table->generate($email_detector_regex_NEW_array);
        echo '<hr>OLD regex';
        $this->table->clear();
        $this->table->set_heading('String In', 'Full pattern', 'mailbox', 'domain');
        echo $this->table->generate($email_detector_regex_OLD_array);
    
    }
    
    function _p($d) {echo'<pre>';print_r($d);echo'</pre>';}
}

/* End of file test.php */


Messages In This Thread
Email addresses with a "+" are not parsed correctly - by El Forum - 08-28-2008, 07:59 PM
Email addresses with a "+" are not parsed correctly - by El Forum - 08-28-2008, 09:43 PM
Email addresses with a "+" are not parsed correctly - by El Forum - 08-28-2008, 09:50 PM
Email addresses with a "+" are not parsed correctly - by El Forum - 08-28-2008, 09:54 PM
Email addresses with a "+" are not parsed correctly - by El Forum - 08-28-2008, 10:17 PM
Email addresses with a "+" are not parsed correctly - by El Forum - 08-28-2008, 10:49 PM
Email addresses with a "+" are not parsed correctly - by El Forum - 08-28-2008, 11:11 PM
Email addresses with a "+" are not parsed correctly - by El Forum - 08-28-2008, 11:38 PM
Email addresses with a "+" are not parsed correctly - by El Forum - 08-29-2008, 09:58 AM
Email addresses with a "+" are not parsed correctly - by El Forum - 08-29-2008, 10:29 AM
Email addresses with a "+" are not parsed correctly - by El Forum - 08-29-2008, 12:07 PM
Email addresses with a "+" are not parsed correctly - by El Forum - 08-29-2008, 12:26 PM
Email addresses with a "+" are not parsed correctly - by El Forum - 08-30-2008, 04:20 PM
Email addresses with a "+" are not parsed correctly - by El Forum - 09-01-2008, 12:02 AM
Email addresses with a "+" are not parsed correctly - by El Forum - 09-10-2008, 10:25 PM
Email addresses with a "+" are not parsed correctly - by El Forum - 09-11-2008, 06:45 AM
Email addresses with a "+" are not parsed correctly - by El Forum - 09-11-2008, 07:47 AM



Theme © iAndrew 2016 - Forum software by © MyBB