title: Java repetitive pattern matching (2)
body: <p>Consider the following regex:</p>
  
  <pre><code>(([^\|])*\|)*([^\|]*)
  </code></pre>
  
  <p>This matches <strong>repetitive string patterns</strong> of the type</p>
  
  <pre><code>("whatever except |" |) {0 to any times} ("whatever except |" |) {1 time}
  </code></pre>
  
  <p>So it should match the following String, which has 17 substrings (16 repeated, plus "  z" as the last one).</p>
  
  <pre><code>"abcd  | e | fg | hijk | lmnop | |   | qrs |   t| uv| w |||||x   y|  z"
  </code></pre>
  
  <p>Indeed, <a href="http://regexpal.com/" rel="nofollow noreferrer">RegexPal</a> verifies that the given regex does match the above string.</p>
  
  <p>Now, I want to get each of the substrings (i.e., "abcd  |", "e |", "fg |", etc.), for which there is no prior knowledge about their number, length etc.</p>
  
  <p>According to a similarly-titled <a href="https://stackoverflow.com/questions/6340364/java-repetitive-pattern-matching">previous StackOverflow post</a> and the documentation of the <code>Matcher</code> class <code>find()</code> method, I just need to do something like</p>
  
  <pre><code>Pattern pattern = Pattern.compile(regex); // regex is the above regex
  Matcher matcher = pattern.matcher(input); // input is the above string
  
  while (matcher.find())
  {
     System.out.println(matcher.group(1));
  }
  </code></pre>
  
  <p>However, when I do this I just get 2 strings printed out: the last repeated substring ("x   y|") and a null value; definitely not the 16 substrings I expect.</p>
  
  <p>A nice thing would also be to <strong>check that a match has actually happened</strong>, before running the <code>find()</code> loop, but I am not sure whether <code>matches()</code>, <code>groupCount() &gt; 0</code>, or some other condition should be used, without doing twice the matching work, given that <code>find()</code> also does matching.</p>
  
  <p>So, <strong>questions</strong>:</p>
  
  <ol>
  <li>How can I get all the 16 repeated substrings?</li>
  <li>How can I get the last substring?</li>
  <li>How do I check that the string matched?</li>
  </ol>