code: private static int countWildcardsOccurrences(String templateMessage, String occurrence) {
          if (templateMessage != null && occurrence != null) {
              final Pattern pattern = Pattern.compile(occurrence);
              final Matcher matcher = pattern.matcher(templateMessage);
              int count = 0;
              while (matcher.find()) {
                  count++;
              }
              return count;
          } else {
              return 0;
          }
      }
docs: Count the number of occurrences of a given wildcard.
  
  @param templateMessage
  Input string
  @param occurrence
  String searched.
  @return The number of occurrences.