How to return a substring from a string that satisfies the regular expression?

Hello.
The question in the title, is there a function in php which:
$substring = preg_???('/\w+@/','info@gmail.com');
$substring === 'gmail.com'; //TRUE

or
$substring = preg_???('/\w+.\w+$/','info@gmail.com');
$substring === 'gmail.com'; //TRUE
March 23rd 20 at 18:53
3 answers
March 23rd 20 at 18:55
Solution
Read the documentation

$matches = [];

$result = preg_match('/\w+.\w+$/','info@gmail.com', $matches);

var_dump($result);
var_dump($matches);
March 23rd 20 at 18:57
Solution
Why would the regular season then?

strpos($string, '@')
explode('@', $string);

and all...
March 23rd 20 at 18:59
Solution
In one line without regexps:
$email = 'info@gmail.com';
echo ltrim(strstr($email, '@'), '@');

Find more questions by tags Regular expressionsPHP