title: StackOverflow Error while trying to match a large String with regex
body: <p>I have a String containing natural numbers and between of them any pattern like (,-) or (,).
  With a while - condition i make sure that the given Strings contains as less numbers as a given window size, e.g. 5.</p>
  
  <p>The condition looks like that:</p>
  
  <pre><code>while(discretizedTs.substring(lagWindowStart).matches("(-?,?\\d+,){5,}")) {
  }
  </code></pre>
  
  <p>Where lagWindowStart jumps to the index of the next number or (-,) pattern.
  For small Strings this regular expression is working fine (as far as tested).
  My Problem is, that for large Strings (and i have to deal with very large Strings normaly) this regular expression caused an SOF.
  This happens for example if the String contains more than 17k characters.</p>
  
  <p>Is there a limitation of the length of a String which is to match? or a limit in time the matching must be completed?
  I did not know how to solve the given problem without regular expressions.
  I hope you have any ideas..</p>
  
  <p>Thank you
  best</p>