In PHP, I want to get all the tags (e.g. @Joe) in a string, but avoid email address (e.g. dave@example.com).
So in:
@Joe hello! @Dave's email address is dave@example.com
I want to only match @Joe and @Dave .
The regex I’m trying is
preg_match_all("([ ^]@[a-zA-Z0-9]+)", $comment, $atMatches);
But this only matches @Dave (after removing leading space).
You could use the
\B(not a word boundry) escape sequence to exclude the matches that have a word (like “dave” in the example text) before it. Something like:By the way, you’re not using proper delimiters in your syntax.