title: Replace all instances of a pattern with regular expressions in Javascript / jQuery
body: <p>First off I don't know much about regex and need to buy a book because it's has proven to me to be difficult to pickup.</p>
  
  <p>Ultimately I want to take a dom element, and replace text within straight brackets "[" and "]" and insert a link around the text, and there may be multiple bracket sets in the string.</p>
  
  <pre><code>function changeTip() {  
          var link = '&lt;a href="' + $('#txtURL').attr('value') + '" target="_blank"&gt;';
          $('.tipoftheweektip').html($('#txtTip').attr("value").replace('[', link).replace(']', '&lt;/a&gt;'));
      }
  </code></pre>
  
  <p>This works except:</p>
  
  <ul>
  <li>doesnt work on the second set of brackets</li>
  <li>if there isnt a closing straight bracket, it deletes all the text before the opening straight bracket</li>
  </ul>
  
  <p>I've looked at examples and because straight brackets are used in the regex code, I cant figure out how to look for a bracket and replace it.  </p>
  
  <p>Anyone out there that has done something similar that they can share?  Thanks in advance.</p>