title: how to split a string into substring by characters like those in regex
body: <p>In a legacy system, regex string are defined with customized token, it looks like regex:</p>
  <p><code>a &amp; (b | c) &amp; !d</code></p>
  <p>and so on.</p>
  <p>Now I would like to first split this string into 4 bean, each contains some mask and text (like a b c and d). I can do this by <code>str.toCharArray()</code> and check each character, but I prefere a idiomatic way to solve this.</p>
  <p><strong>UPDATE:</strong></p>
  <p>What I want to have is like <code>findNext</code>, that can return the first string that is split by any character in a group.</p>
  <pre><code>String a = &quot;a&amp;(b|c)&amp;!d&quot;;
  String tokens = &quot;&amp;(|)!&quot;;
  b1 = a.findNext(tokens, 0);
  Assert.equal(b1.text, &quot;a&quot;);
  Assert.equal(b1.pos, 0);
  
  b2 = a.findNext(tokens, b1.pos+1);
  Assert.equal(b2.text, &quot;b&quot;);
  Assert.equal(b2.pos, 3);
  
  b3 = a.findNext(tokens, b2.pos+1);
  Assert.equal(b2.text, &quot;c&quot;);
  Assert.equal(b2.pos, 5);
  </code></pre>