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