Nasıl Regex kullanarak bir dize içinde e-posta kapmak mı?
Aşağıdaki gibi benim dize
"First Last <first.last@email.com>"
Ben "first.last @ gmail.com" yakala ve bir yere saklamak istiyoruz.
Şimdiden teşekkürler!
^[^<]*<([^>]*)>$
Geri kalanı için, bkz: http://stackoverflow.com/questions/201323/what-is-the-best-regular-expression-for-validating-email-addresses
Regex olmadan (ve muhtemelen çok daha hızlı):
$string = "First Last <first.last@email.com>";
echo substr($string, strpos($string, '<') +1, -1);
veya
echo trim(strstr("First Last <first.last@email.com>", '<'), '<>');
hem de verecektir
first.last@email.com
Eğer nihai sonucu doğrulamak gerekiyorsa kullanın
filter_var($eMailString, FILTER_VALIDATE_EMAIL);