Java正则表达式和转义元字符

Raj*_*nth 3 java regex

我正在尝试编写regexp来匹配嵌入在两个花括号之间的标记.例如,如果缓冲区Hello {World},我想从String中获取"World"标记.当我使用像\{*\}eclipse 这样的regexp时会显示错误信息

转义序列无效(有效转义序列\b \t \n \f \r \" \' \\)

谁能帮帮我吗?我是新手使用正则表达式.

anu*_*ava 5

使用此代码匹配{和之间的字符串}

String str = "if buffer Hello {World}";
Pattern pt = Pattern.compile("\\{([^}]*)\\}");
Matcher m = pt.matcher(str);
if (m.find()) {
    System.out.println(m.group(0));
}
Run Code Online (Sandbox Code Playgroud)