I am trying to find a regular expression that matches if there is a true mention in it. To be mentioned, a line cannot begin with “@” and cannot contain “RT” (case insensitive), and “@” must begin with a word.
In the examples, I commented on the desired result.
Some examples:
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 ",
Current output:
Example 1: Sentence: "Hi @peter, I like your car " <- MATCH Sentence: "@peter I don't think so!" <- MATCH Sentence: "Helo!! :@ how are you!" <- NO MATCH Sentence: "Yes @peter i'll eat them this evening! RT @peter: hey @you, do you want your pancakes?" <- MATCH Sentence: "Helo!! ineed@aser.com how are you!" <- MATCH Sentence: "@peter is the best friend you could imagine. RT @juliet: @you do you know if @peter it awesome?" <- MATCH
EDIT:
I need this in regex beacause, it can be used in MySQL and other languages too. I am not looking for any usernames. I just want to know if the string is mentioned or not.
LDK
source share