Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can try to use <code>split</code> method with <code>(?&lt;=\\G\\d+,\\d+,\\d+),</code> regex</p> <p>Demo</p> <pre><code>String data = "0,0,1,2,4,5,3,4,6"; String[] array = data.split("(?&lt;=\\G\\d+,\\d+,\\d+),"); //Magic :) // to reveal magic see explanation below answer for(String s : array){ System.out.println(s); } </code></pre> <p>output:</p> <pre><code>0,0,1 2,4,5 3,4,6 </code></pre> <p>Explanation</p> <ul> <li><code>\\d</code> means one digit, same as [0-9], like <code>0</code> or <code>3</code></li> <li><code>\\d+</code> means one or more digits like <code>1</code> or <code>23</code></li> <li><code>\\d+,</code> means one or more digits with comma after it, like <code>1,</code> or <code>234,</code> </li> <li><code>\\d+,\\d+,\\d+</code> will accept three numbers with commas between them like <code>12,3,456</code></li> <li><code>\\G</code> means last match, or if there is none (in case of first usage) start of the string</li> <li><code>(?&lt;=...),</code> is <a href="http://www.regular-expressions.info/lookaround.html#lookbehind" rel="nofollow noreferrer">positive look-behind</a> which will match comma <code>,</code> that has also some string described in <code>(?&lt;=...)</code> before it</li> <li><code>(?&lt;=\\G\\d+,\\d+,\\d+),</code> so will try to find comma that has three numbers before it, and these numbers have aether start of the string before it (like <code>^0,0,1</code> in your example) or previously matched comma, like <code>2,4,5</code> and <code>3,4,6</code>.</li> </ul> <hr> <p>Also in case you want to use other characters then digits you can also use other set of characters like</p> <ul> <li><code>\\w</code> which will match alphabetic characters, digits and <code>_</code></li> <li><code>\\S</code> everything that is not white space</li> <li><code>[^,]</code> everything that is not comma</li> <li>... and so on. More info in <a href="http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html" rel="nofollow noreferrer">Pattern documentation</a></li> </ul> <hr> <p>By the way, this form will work with split on every 3rd, 5th, 7th, (and other odd numbers) comma, like <code>split("(?&lt;=\\G\\w+,\\w+,\\w+,\\w+,\\w+),")</code> will split on every 5th comma. </p> <p>To split on every 2nd, 4th, 6th, 8th (and rest of even numbers) comma you will need to replace <code>+</code> with <code>{1,maxLengthOfNumber}</code> like <code>split("(?&lt;=\\G\\w{1,3},\\w{1,3},\\w{1,3},\\w{1,3}),")</code> to split on every 4th comma when numbers can have max 3 digits (0, 00, 12, 000, 123, 412, 999).</p> <p>To split on every 2nd comma you can also use this regex <code>split("(?&lt;!\\G\\d+),")</code> based on my <a href="https://stackoverflow.com/a/16486373/1393766">previous answer</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload