在java中将{rammdmdmd}替换为%s

在java中将{rammdmdmd}替换为%s,java,string,core,Java,String,Core,如何使用JAVA将下面句子中的{{……}}替换为%s String str="Your appointment with {{provider_name}} on {{start_time}} is cancelled at {{careCenter_name}}. Call {{careCenter_phoneNumber}} for queries."; 结果应该是这样 Your appointment with %s on %s is cancelled at %s. Call %s f

如何使用JAVA将下面句子中的
{{……}}
替换为
%s

String str="Your appointment with {{provider_name}} on {{start_time}} is cancelled at {{careCenter_name}}. Call {{careCenter_phoneNumber}} for queries.";
结果应该是这样

Your appointment with %s on %s is cancelled at %s. Call %s for queries.";

使用或

将此正则表达式与
字符串一起使用。replaceAll()
方法:

str.replaceAll("\\{\\{.+?\\}\\}", "%s")
如果要处理用两个大括号括起来的实际值,可以使用m.group(1)。

尝试使用以下正则表达式:-

String s = "Your appointment with {{provider_name}} on {{start_time}}";
s = s.replaceAll("\\{.*?\\}\\}", "%s");
输出:- 您与%s在%s上的约会

String s = "Your appointment with {{provider_name}} on {{start_time}}";
s = s.replaceAll("\\{.*?\\}\\}", "%s");