次の行でエラーが発生します。
Pattern pattern = Pattern.compile(word + "\\(.*\\)");
それは言います:
Exception in thread "AWT-EventQueue-0" java.util.regex.PatternSyntaxException: Unclosed group near index 14
このエラーは、エスケープされていない特殊文字を残した場合に発生することはわかっていますが、そこには何も表示されません..
完全なコード:
StyleConstants.setItalic(set, true);
for (String word : code.split("\\s")) {
Pattern pattern = Pattern.compile(word + "\\(.*\\)");
Matcher matcher = pattern.matcher(word);
while (matcher.find()) {
doc.setCharacterAttributes(matcher.start(), word.length(), set, true);
}
}
コードは文字列です。コードを展開し、すべての単語をチェックします。単語が一致した場合、色を付けます