How can we extract string ‘abc.com’ from a string ‘http://[email protected]’ using regular _expression of php?

How can we extract string ‘abc.com’ from a string ‘http://info@abc.com’ using regular _expression of php?

To extract the string 'abc.com' from string ‘http://[email protected]’ we are going to use preg_match. Preg_match is used for matching strings with regular expressions.
Its syntax is:

int preg_match( string $pattern , string $subject [,array &$matches [, int $flags = 0 [, int$offset = 0 ]]] )

We use preg_match with the first two parameters if we are simply checking for matching. If we want to extract the matched string, then we used the third parameter.
In our case, the syntax will be:

preg_match(“/.*@(.*)$/”,”http://[email protected]”,$result);
echo $result[1];

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.