private void applyRegexHighlighting(JTextComponent comp, Pattern pattern) {
    Matcher matcher = pattern.matcher(comp.getText());
    
    Highlighter h = comp.getHighlighter();
    h.removeAllHighlights();
          
    while(matcher.find()) {
      try {
        h.addHighlight(matcher.start(), matcher.end(), regexPainter);
      }
      catch(Exception e) {
        throw new RuntimeException(e);
      }
    }
    
  }