-6

I need a regex to match pattern from web page. I want to extract all name and email addresses. Text is in a HTML table like:

Name <email@test.com>

Update

Name 1 <email1@test.com>
Name 2 <email2@test.com>
Name 3 <email1@test.com>

Like this.

Thanks, Uday

uday8486
  • 1,203
  • 2
  • 13
  • 22

1 Answers1

0

Without a clear email pattern you could use something like this:

[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+\.[a-z]{2,3}(\.[a-z]{2})?

Or in code

$re = '/[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+\.[a-z]{2,3}(\.[a-z]{2})?/';
$str = '';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
var_dump($matches);

Where $str is the HTML to parse.

Rudy Palacios
  • 122
  • 2
  • 8
  • through this I get the email, but I need the name as well which does not get extracted from this pattern. – uday8486 Aug 11 '17 at 06:19
  • Please paste the actual structure, or a fragment of the actual HTML you are trying to parse, it will be easier to find the pattern and adjust the regex. – Rudy Palacios Aug 11 '17 at 06:38