title: Regular expression in Javascript: table of positions instead of table of occurrences
body: <p>Regular expressions are most powerful. However, the result they return is sometimes useless:</p>
  
  <p>For example: </p>
  
  <p>I want to manage a CSV string using semicolons.
  I define a string like:</p>
  
  <pre><code>var data = "John;Paul;Pete;Stuart;George";
  </code></pre>
  
  <p>If I use the instruction:  </p>
  
  <pre><code>var tab = data.match(/;/g)
  </code></pre>
  
  <p>after what, "tab" contains an array of 4 ";" :</p>
  
  <pre><code>tab[0]=";", tab[1]=";", tab[2]=";", tab[3]=";"
  </code></pre>
  
  <p>This array is not useful in the present case, because I knew it even before using the regular expression.</p>
  
  <p>Indeed, what I want to do is 2 things:</p>
  
  <ul>
  <li>1stly: Suppress the 4th element (not "Stuart" as "Stuart", but "Stuart" as 4th element)</li>
  <li><p>2ndly: Replace the 3rd element by "Ringo" so as to get back (to where you once belonged!) the following result:</p>
  
  <p><code>data == "John;Paul;Ringo;George";</code></p></li>
  </ul>
  
  <p>In this case, I would greatly prefer to obtain an array giving the positions of semicolons:</p>
  
  <pre><code>tab[0]=4, tab[1]=9, tab[2]=14 tab[3]=21
  </code></pre>
  
  <p>instead of the useless (in this specific case)</p>
  
  <pre><code>tab[0]=";", tab[1]=";", tab[2]=";", tab[3]=";"
  </code></pre>
  
  <p>So, here's my question: Is there a way to obtain this numeric array using regular expressions?</p>