title: How to replace part of a string using regex
body: <p>i need to replace a part of a string in Javascript</p>
  
  <p>The following example should clarify what i mean</p>
  
  <pre><code>var str = "asd[595442/A][30327][0]";
  var strToReplace = "30333";
  
  var strDesiredResult = "asd[595442/A][30333][0]";
  </code></pre>
  
  <p>Basically it means the second area within the brackets should get replaced with another string</p>
  
  <p>How to do that?</p>
  
  <p>What i did so far is something like this :</p>
  
  <pre><code>var str = "asd[595442/A][30327][0]";
  var regex = /asd\[(.*)\]\[(.*)\]\[(.*)\]/;
  var arrMatches = regex.exec(str);
  </code></pre>
  
  <p>The string appears in arrMatches[2] correctly, and i could replace this. But what happens if in arrMatches[1] is the same string ?</p>
  
  <p>Because it should only replace the value in the second bracket area.</p>