Finally, I adopted regex("/@[^\s@\/]+/") for preg_match_all().
Reason that I excluded "\+": Q2A allows space to user handle.
If user handle contains space, we connect words with "+" character.
e.g. "John Doe" >>>"@John+Doe"
Reference information:
This is a function to get array of userid at q_post / a_post / c_post / q_edit / a_edit / c_edit event.
I hope this will be useful for someone.
function mention($event, $userid, $handle, $cookieid, $params) {
$userids = array();
$regularex = "/@[^\s@\/]+/";
$type = explode("_", $event);
$post_types = Array("q", "a", "c");
$event_types = Array("post", "edit");
if (!in_array($type[0], $post_types) or !in_array($type[1], $event_types))
return $userids;
if(!array_key_exists('text', $params))
return $userids;
$tohandles = Array();
if(isset($params["title"])) {
if(preg_match_all($regularex, $params["title"], $matches)) {
foreach ($matches[0] as $matche) {
$item = trim($matche, "@ \t\n\r\0\x0B");
$item = str_replace('+', ' ', $item);
if (!in_array($item, $tohandles))
$tohandles[] = $item;
}
}
}
if(!empty($params["text"])) {
if(preg_match_all($regularex, $params["text"], $matches)) {
foreach ($matches[0] as $matche) {
$item = trim($matche, "@ \t\n\r\0\x0B");
$item = str_replace('+', ' ', $item);
if (!in_array($item, $tohandles))
$tohandles[] = $item;
}
}
}
if(count($tohandles)) {
$userids = qa_handles_to_userids($tohandles);
foreach($userids as $handle => $userid) {
if(empty($userid))
unset($userids[$handle]);
}
}
return $userids;
}
Thanks again.