title: Ruby regex to find words starting with @
body: <p>I'm trying to write a very simple regex to find all words in a string that start with the symbol <code>@</code>. Then change the word to a link. Like you would see in a Twitter where you can mention other usernames.</p>
  
  <p>So far I have written this</p>
  
  <pre><code>def username_link(s)
    s.gsub(/\@\w+/, "&lt;a href='/username'&gt;username&lt;/a&gt;").html_safe
  end
  </code></pre>
  
  <p>I know it's very basic and not much, but I'd rather write it on my own right now, to fully understand it, before searching GitHub to find a more complex one. </p>
  
  <p>What I'm trying to find out is how can I reference that matched word and include it in the place of <code>username</code>. Once I can do that i can easily strip the first character, <code>@</code>, out of it.</p>
  
  <p>Thanks.</p>