How do find the word starting with the @ symbol within a string?

i want to find a word starting with the @ symbol. when i find the word, i want to make it into a hyperlink so the user can click on the username.

so for example, the user creates a status "hey everyone! you guys have to go checkout @username. hes so cool!"

i want to take that word that starts with the @ symbol inside the string before it goes into the database, and create a hyperlink around it so when i grab it from the database, it links directly the users profile page already. how can i do this?

//document.write(state_array[0]); just for testing every thing is working.

//looping through the emelents of the array : var i; var array_length = state_array.length; for ( i=0 ; i < array_length; i++ ) { //indexOf() returns the position of a certain character in a given string. if (state_array[i].indexOf('@') == '0') { document.write(state_array[i] + ''); }