I’ve been learning regular expressions lately and am wondering if this is possible:
I am pulling in a twitter feed and I have access to tweets, but when I want to display those tweets on my web site – links, @ replies and hash tags are all unlinked. So I’ve begun the process of linking them up. I’m onto the @ replies and have a question:
Here’s my regular expression:
$content = '@jason is awesome.';
$reply = '/@(\w+)/';
if(preg_match($reply, $content, $matches)){
var_dump($matches[0]);
}
So that will return ‘@jason’ but I want to know if there is a way to search for it with the @, but only return what comes after it – just ‘jason’. How do I do this with regular expressions?
As Double mentioned, $matches[1] will give you want you want. $matches[0] is special, it contains the whole matching string. The subsequent items in the list are the captured groups.