fork download
  1. <?php
  2.  
  3. $tests = ['name@mail.ru','@twitterUser','vas.pupkin@gmail.com.com'];
  4. foreach( $tests AS $i=>$e) {
  5. if( preg_match( '/.+(?=@)/', $e, $matches)) {
  6. echo $matches[0].PHP_EOL;
  7. } else {
  8. echo "no match\n";
  9. }
  10. }
Success #stdin #stdout 0.03s 52480KB
stdin
Standard input is empty
stdout
name
no match
vas.pupkin