title: Using a Regex to match all emotes, not just the first match?
body: <p>I'm trying to match emotes and replace the emote characters with an image. I have the following:</p>
  
  <pre><code>var emotes ={
      "laughing": Array(":))"),
      "smile": Array(":o)",":-)",":)","=]","=)"),
      "sick": Array(":-&amp;")
  };
  </code></pre>
  
  <p>Then I find the matches using:</p>
  
  <pre><code>function emoticons(html){
      for(var emoticon in emotes){
          for(var i = 0; i &lt; emotes[emoticon].length; i++){
              // Replace the emote with the image
              html = html.replace(emotes[emoticon][i],"&lt;img src=\""+icon_folder+"/face-"+emoticon+".png\" class=\"emoticonimg\" /&gt;","g");
          }
      }
      return html;
  }
  return this.each(function(){
      $(this).html(emoticons($(this).html()));
  });
  </code></pre>
  
  <p>The issues are:</p>
  
  <ol>
  <li>If the html equals ":) :) :) :) :)" It is only replacing the first instance, not all</li>
  <li>Laughing, :)), it being picked up as a smile with a trailing )</li>
  <li>sick ends up outputting amp; html? "<code>&lt;img src="/images/emoticons/face-sick.png" class="emoticonimg"&gt;amp;</code>" at the end</li>
  </ol>
  
  <p>Any RegEx experts able to lend a hand? Thanks</p>