Page 1 of 1

php to find @ symbol

Posted: Fri Jan 16, 2009 2:59 pm
by Citizen
I need php to find any word in a string that begins with an @ symbol. It has to be by itself:

For instance:

@myname = match
asdf@myname = not a match
@ myname = not a match
@@ = not a match
@@myname = not a match

Any ideas?

Re: php to find @ symbol

Posted: Fri Jan 16, 2009 4:23 pm
by Burrito

Code: Select all

 
preg_match("/(^@[^@\s]+.*?)$/",$string,$matches);
 
untested but that should match all of your cases above....

Re: php to find @ symbol

Posted: Sat Jan 17, 2009 12:55 am
by prometheuzz
Citizen wrote:I need php to find any word in a string ...
You will need to define what a "word" is for you. The suggestion of the previous poster will also match strings like:

Code: Select all

"@~~~~"
"@abc,"
"@1ab2"
etc.