我在这一行收到错误:
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);
}
}
代码是一个字符串。它分解代码并检查每个单词。如果单词匹配,则为其着色