title: Java - regex to match successive digits or character in a string
body: <p>I have a client requirement that while choosing the password the user can't use more then three successive characters or digits in the password string. For example: </p>
  
  <pre><code>abc -&gt;&gt; allowed
  abcd -&gt;&gt; not allowed
  wxy -&gt;&gt; allowed
  wxyz -&gt;&gt; not allowed
  stu -&gt;&gt; allowed
  stuv -&gt;&gt; not allowed
  </code></pre>
  
  <p>and to be specific ab, bc, kl, op these are allowed. I mean successive digits or characters are allowed up to length three. And any thing more then three length(successive) is not allowed. Like 12345, 123456, 456789, abcdef, pqrstuv - these are not allowed.</p>
  
  <p>and same goes for digits. Examples: </p>
  
  <pre><code>123 -&gt;&gt; allowed
  1234 -&gt;&gt; not allowed
  456 -&gt;&gt; allowed
  4567 -&gt;&gt; not allowed
  345 -&gt;&gt; allowed
  3456 -&gt;&gt; not allowed
  </code></pre>
  
  <p>and 12, 45, 78, 89 these are allowed. </p>
  
  <p>Is it achievable with regex? If so then a little help is needed. </p>
  
  <p>I have tried the following regex : </p>
  
  <pre><code>^(?:(?!(?:abcd|bcde|cdef|defg|efgh|fghi|ghij|hijk|ijkl|jklm|klmn|lmno|mnop|nopq|opqr|pqrs|qrst|rstu|stuv|tuvw|uvwx|vwxy|wxyz|(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z)\1{3})).)*
  </code></pre>
  
  <p>but this regex doesn't give the proper out put. Like it founds a match for both the strings "abc" and "acm".</p>
  
  <p>For testing my regex I am using the following regex tester:</p>
  
  <p><a href="http://www.regexplanet.com/advanced/java/index.html" rel="nofollow">http://www.regexplanet.com/advanced/java/index.html</a></p>