How to get emails from the page or string using regular expression

    Here is the code used to extract emails from string or page content
    <?php
    //$string will be simple string or page content

       
    $regx="/([\s]*)([_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*([ ]+|)@([ ]+|)([a-zA-Z0-9-]+\.)+([a-zA-Z]{2,}))([\s]*)/i";            
    preg_match_all($regx, $string, $match);
    // here $match is array returned with all the email ids
    ?>
    5
    Average: 5 (1 vote)