我试图找到匹配的正则表达式,如果推文是真正的提及.值得一提的是,字符串不能以"@"开头,不能包含"RT"(不区分大小写),"@"必须以单词开头.
在示例中,我评论了所需的输出
一些例子:
function search($strings, $regexp) {
$regexp;
foreach ($strings as $string) {
echo "Sentence: \"$string\" <- " .
(preg_match($regexp, $string) ? "MATCH" : "NO MATCH") . "\n";
}
}
$strings = array(
"Hi @peter, I like your car ", // <- MATCH
"@peter I don't think so!", //<- NO MATCH: the string it's starting with @ it's a reply
"Helo!! :@ how are you!", // NO MATCH <- it's not a word, we need @(word)
"Yes @peter i'll eat …Run Code Online (Sandbox Code Playgroud)