title: Run functions for all occurrences of content in string enclosed in square brackets
body: <p>I have a string. The data is from a text area and contains occurrences of (varying) content enclosed in square brackets. </p>
  
  <p>I would like to run functions (e.g. replace) on the string content that is enclosed in square brackets, then update the original string to reflect the changes made.</p>
  
  <p>Example</p>
  
  <p><code>not this [potentially act on this token] not this [potentially act on this token] not this</code></p>
  
  <p>I think some of the following may be involved but I can’t figure out how to implement a working solution. I wouldn’t like to use jQuery or external libraries.</p>
  
  <ul>
  <li>Match + RegEx <a href="http://regexr.com/3a188" rel="nofollow">Something like this</a>.</li>
  <li>indexOf. Possibly to get the content of the match if it can’t be done with RegEx alone.</li>
  <li>For each. As there are numerous instances of content enclosed in square brackets.</li>
  </ul>
  
  <p>Here’s a starting point <a href="http://jsfiddle.net/gregabbott/fdtxvyo7/3/" rel="nofollow">JSFiddle</a>.</p>
  
  <p>If anyone could be of any assistance, I’d really appreciate it.</p>
  
  <p>Thank you very much.</p>