code: public static int preg_match(Pattern pattern, String subject) {
          int matches=0;
          Matcher m = pattern.matcher(subject);
          while(m.find()){ 
              ++matches;
          }
          return matches;
      }
docs: Matches a string with a pattern.
  
  @param pattern
  @param subject
  @return