我有以下字符串。该字符串包含提到的三个用户的数据 (@[ID:username__FULLNAME])。我想提取它们。我试过下面的代码,但没有得到想要的结果。
ID is integer type
username and FULLNAME may contain numbers, letter and all kind of special chars.
$t = 'Hi @[4232:mark__MΛRK ATTLEY] how are you ?
Hi @[4232:ryan__RYΛN вυηту] how are you ?
Hi @[4232:david__DΛVID शाहिद ] how are you ?
';
我的 PHP 代码:
$pattern = "|(?:(@\[[0-9]+:[\s\S(?!\])]+\]*))|";
preg_match_all($pattern, $string, $mentionList, PREG_PATTERN_ORDER);
print_r($mentionList);
当前结果:
Array
(
[0] => Array
(
[0] => @[4232:mark__MΛRK ATTLEY] how are you ?
Hi @[4232:ryan__RYΛN вυηту] how are you ?
Hi @[4232:david__DΛVID शाहिद] how are you ?
)
[1] => Array
(
[0] => @[4232:mark__MΛRK ATTLEY] how are you ?
Hi @[4232:ryan__RYΛN вυηту] how are you ?
Hi @[4232:david__DΛVID शाहिद] how are you ?
)
)
预期结果:
Array
(
[0] => Array
(
[0] => @[4232:mark__MΛRK ATTLEY]
[1] => @[4232:ryan__RYΛN вυηту]
[2] => @[4232:david__DΛVID शाहिद ]
)
)
有人可以帮我得到想要的结果吗?
谢谢。