我想替换所有实例
{IMAGE:imagename}与imagepath,
{MESSAGE:messagename}带有消息。
我尝试使用字符串类的 replaceAll 函数,但无法实现。
示例代码:
String str = "HELLO WORLD {IMAGE:abcd}";
str = str.replaceAll("{IMAGE:abcd}", "defg");
输出 :
Exception in thread "main" java.util.regex.PatternSyntaxException: Illegal repetition
{IMAGE:abcd}
at java.util.regex.Pattern.error(Pattern.java:1713)
at java.util.regex.Pattern.closure(Pattern.java:2775)
at java.util.regex.Pattern.sequence(Pattern.java:1889)
at java.util.regex.Pattern.expr(Pattern.java:1752)
at java.util.regex.Pattern.compile(Pattern.java:1460)
at java.util.regex.Pattern.<init>(Pattern.java:1133)
at java.util.regex.Pattern.compile(Pattern.java:823)
at java.lang.String.replaceAll(String.java:2189)
at com.example.WorkSheet.main(WorkSheet.java:28)