code: public final String trimFrom(String s) {
      int first;
      int last;
  
      // removes leading matches
      for (first = 0; first < s.length(); ) {
        final int codePoint = s.codePointAt(first);
        if (!matches(codePoint)) {
          break;
        }
        first += Character.charCount(codePoint);
      }
  
      //remove trailing matches
      for (last = s.length() - 1; last >= first; --last) {
        if (Character.isLowSurrogate(s.charAt(last))) {
          --last;
        }
        if (!matches(s.codePointAt(last))) {
          break;
        }
      }
  
      return s.substring(first, last + 1);
    }
docs: Returns a copy of the input string with all leading and trailing codepoints matching this
  matcher removed