code: public static int countRegexpMatches(String str, String regexp) {
      if (isEmpty(str) || isEmpty(regexp)) {
          return 0;
      }
      Pattern pattern = Pattern.compile(regexp);
      Matcher matcher = pattern.matcher(str);
      int i = 0;
      while (matcher.find()) {
        i++;
      }
      return i;
    }
docs: <p>Counts how many times the regexp appears in the larger String.</p>
  
  <p>A <code>null</code> or empty ("") String input returns <code>0</code>.</p>
  
  <pre>
  GosuStringUtil.countMatches(null, *)       = 0
  GosuStringUtil.countMatches("", *)         = 0
  GosuStringUtil.countMatches("abba", null)  = 0
  GosuStringUtil.countMatches("abba", "")    = 0
  GosuStringUtil.countMatches("abba", "a")   = 2
  GosuStringUtil.countMatches("abba", "ab")  = 1
  GosuStringUtil.countMatches("abba", ".b")  = 2
  GosuStringUtil.countMatches("abba", "xxx") = 0
  </pre>
  
  @param str  the String to check, may be null
  @param regexp  the regexp to count, may be null
  @return the number of occurrences, 0 if either String is <code>null</code>