title: StackOverflow when checking if one string is contained in another
body: <p>I currently have a method that is supposed to take two strings and then check if one string exists as a substring in other. It doesn't check both ways so the way in which I pass my strings to the method determines what string is looked for in the other.</p>
  
  <p>Currently I am getting a <strong>stackoverflow</strong> error.</p>
  
  <pre><code>public boolean checkMatch(String text, String regex, int i){
  
      int regexL = regex.length();
  
          if(i == regexL){
              return true;
          }   
  
          System.out.println(text.charAt(i) + " " + regex.charAt(i));
  
          if(text.charAt(i) == regex.charAt(i)){
              return checkMatch(text, regex, i++);
          }
          else if(text.charAt(i) != regex.charAt(i)){
  
              if(text.substring(1) == ""){
                  return false;
              }               
              else if(text.substring(1) != ""){
                  return checkMatch(text.substring(1), regex, 0);
              }
          }
          return false;
  
  }
  </code></pre>
  
  <p>I am running a test using my first name as an example.</p>
  
  <pre><code>@Test public void test_52() {
      assertEquals(true, checkMatch("Samual", "mu", 0));
  }
  </code></pre>
  
  <p>the console looks like this after it overflows.</p>
  
  <p>S m</p>
  
  <p>a m</p>
  
  <p>m m</p>
  
  <p>m m</p>
  
  <p>m m</p>
  
  <p><em>etc</em></p>
  
  <p>Where am I going wrong? Am I iterating wrong? The stack trace shows that it seems to be getting caught on this line.</p>
  
  <pre><code>return checkMatch(text, regex, i++);
  </code></pre>
  
  <p>But the defect point is rarely the point of failure. Sorry for the wall of text and code.</p>