private int posMatch(String text, String pat) {
      int i = 0, j = 0;
      int lens = text.length();
      int lenp = pat.length();
      while (i < lens && j < lenp) {
        if (text.charAt(i) == pat.charAt(j)) {
          i++;
          j++;
        } else if (j == 0)
          i++;
        else
          j = failure[j - 1] + 1;
      }
      return ((j == lenp) ? (i - lenp) : -1);
    }