code: public static Pattern longest(final Pattern... patterns) {
      return new Pattern() {
        @Override
        public int match(CharSequence src, int begin, int end) {
          int r = MISMATCH;
          for (Pattern pattern : patterns) {
            int l = pattern.match(src, begin, end);
            if (l > r)
              r = l;
          }
          return r;
        }
      };
    }
docs: Returns a {@link Pattern} that tries all of {@code patterns}, and picks the one with the
  longest match length. If two patterns have the same length, the first one is favored.