protected void removeMatches(Map<Integer, List<MatchResult>> matches, int start, int end) {
    if (matches == null) {
      return;
    }
    for (int offset : matches.keySet()) {
      List<MatchResult> offsetMatches = matches.get(offset);

      ListIterator<MatchResult> iterator = offsetMatches.listIterator();
      while (iterator.hasNext()) {
        MatchResult match = iterator.next();

        // the start and end position in the document for this matched result
        int _start = match.getOffset(), _end = _start + match.getLength();

        if (_start >= end || _end <= start) {
          // out of the range
          continue;
        }
        if (_start >= start && _end <= end) {
          // fit or within range
          iterator.remove();
        } else if (_end <= end) {
          // overlap with the start
          // remove the style within the range and remain those without the range
          iterator.set(new MatchResult(_start, start - _start, match.getStyleKey(), match.isBold()));
        } else if (_start >= start) {
          // overlap with the end
          // remove the style within the range and remain those without the range
          iterator.set(new MatchResult(end, _end - end, match.getStyleKey(), match.isBold()));
        }
      }
    }
  }