title: How to split string at every nth occurrence of character in Java
body: <p>I would like to split a string at every 4th occurrence of a comma <code>,</code>.</p>
  
  <p>How to do this? Below is an example:</p>
  
  <pre><code>String str = "1,,,,,2,3,,1,,3,,";
  
  Expected output:
  array[0]: 1,,,,
  array[1]: ,2,3,,
  array[2]: 1,,3,,
  </code></pre>
  
  <p>I tried using Google Guava like this:</p>
  
  <pre><code>Iterable&lt;String&gt; splitdata = Splitter.fixedLength(4).split(str);
  output: [1,,,, ,,2,, 3,,1, ,,3,, ,]
  </code></pre>
  
  <p>I also tried this:</p>
  
  <pre><code>String [] splitdata = str.split("(?&lt;=\\G.{" + 4 + "})");
  output: [1,,,, ,,2,, 3,,1, ,,3,, ,]
  </code></pre>
  
  <p>Yet this is is not the output I want. I just want to split the string at every 4th occurrence of a comma.</p>
  
  <p>Thanks.</p>