This is based on Niranjan's answer, assuming you have an input email address, and> characters). Instead of using regex to capture email addresses, here I get the text part between the <and> characters. Otherwise, I use the string to get all the email. Of course, I did not do any verification on the email address, it will depend on your scenario.
<?php $string = 'Ruchika < ruchika@example.com >'; $pattern = '/<(.*?)>/i'; preg_match_all($pattern, $string, $matches); var_dump($matches); $email = $matches[1][0] ?? $string; echo $email; ?>
Here is a forked demonstration .
Of course, if my assumption is wrong, then this approach will fail. But, based on your data, I believe that you would like to receive emails enclosed inside <and> characters.
source share