如何从preg_replace中提取数据

I wan to be able to get data from a preg_replace function or a str_replace function. For example i want to convert any string beginning with @. But i want to extract that string that begins with @ and put it in my database! So how can i just extract that specific word that begins with @?

Here is my code:

$string = "@james is awespome";

$convert = preg_replace('@','<a href="#">@$1</a>','$string');

mysql_query( insert stuff);

i want to be able to insert @james or james in the database

Use preg_match instead:

$string = "@james is awespome";
preg_match('/@([A-Za-z0-9_]{1,15})/', $string, $convert); 
//matches @<string of length upto 15 chars>
echo $convert[0];

Outputs:

@james

Demo!

<?php
$string = "@james is awespome";
$convert = preg_replace('/(@.*?)\s.*/','$1', $string);
print $convert;

Prints @james