Reputation: 1745
Does any one have an idea how to match something like
<[email protected]>
I tried this regular expression
\<(.?*)\>
but this matches also <sddsds>
I want it to match where inside <>
is an email with @
sign.
Upvotes: 2
Views: 108
Reputation: 115
You can use this:
$regex = '/^\w+([.-]?\w+)*@\w+([.-]?\w+)*(\.\w{2,3})+$/'
Upvotes: 0
Reputation: 627082
You can use
<([^<>@]+@[^<>@]+)>
See the regex demo. Details:
<
- a <
char([^<>@]+@[^<>@]+)
- Group 1: any one or more chars other than <
, >
and @
, a @
char and then again any one or more chars other than <
, >
and @
>
- a >
char.See the PHP demo:
$str = "<[email protected]>\n<tatacom>\n<t@ata@com>";
$re = '/<([^<>@]+@[^<>@]+)>/';
if (preg_match_all($re, $str, $matches)) {
print_r($matches[1]);
}
// => Array( [0] => [email protected] )
Upvotes: 2