public static Collection<MessageFragmentStyle> colorizeRegex(Style style, String text, Pattern regex, int group) {
    ArrayList<MessageFragmentStyle> list = new ArrayList<>();
    Matcher matcher = regex.matcher(text);
    while (matcher.find()) {
      int start = matcher.start(group);
      int end = matcher.end(group);
      if (end - start > 0) {
        MessageFragmentStyle messageFragmentStyle = new MessageFragmentStyle(start, end - start, style, false);
        list.add(messageFragmentStyle);
      }
    }
    return list;
  }
Apply styles on StyledDocument using regular expression

@param style
         style to apply
@param text
         text to be tested by regular expression, fragment from document
@param regex
         regular expression
@param group
         group to apply
olv-core/src/main/java/pl/otros/logview/gui/message/MessageColorizerUtils.java