title: Check if string has any consecutive repeating substring in it
body: <p>I want to accept only strings that do not have any substring repeated three times consecutively in them. The substring is not known in advance. For example, "a4a4a4123" contains "a4"; "abcdwwwabcd" - "w"; "abcde" - valid, no triple repeats.</p>
  
  <p>I tried to implement it myself, but this only works for substrings with one letter:</p>
  
  <pre><code>public bool IsValid(string password)
  {
      var validate = true;
      char lastLetter = ' ';
      var count = 1;
  
      for (int pos = 0; pos &lt; password.Length; pos++)
      {
          if (password[pos] == lastLetter)
          {
              count++;
  
              if (count &gt; 2)
              {
                  validate = false;
                  break;
              }
          }
          else
          {
              lastLetter = password[pos];
              count = 1;
          }
      }
  
      return validate;
  }
  </code></pre>