Reputation: 2454
The problem with this method is I don't get anything after .
$string = "this is a [email protected] email address";
preg_match('/\b(\w*@\w*)\b/', $string, $matches);
The result of $matches
is
Array
(
[0] => email@test
)
Is it possible to alter the regex to ignore them?
Upvotes: 0
Views: 38
Reputation: 3446
.
is not a part of \w
. Alter your RegEx to something like: \b([\w.-]+@[\w.-]+)\b
.
Upvotes: 0
Reputation: 149000
Try using a character class ([...]
). Also you probably want to use a one-or-more quantifier (+
):
preg_match('/\b([\w.]+@[\w.]+)\b/', $string, $matches);
You can include any other characters (such as -
or +
) you'd like to match as well.
Upvotes: 2