Java 非常简单的专家正则表达式
我想使用正则表达式查找和替换文本中的占位符Java 非常简单的专家正则表达式,java,regex,Java,Regex,我想使用正则表达式查找和替换文本中的占位符 String s = "This is a test {replace_me}. And this is another {replace_me_too}." s.replaceFirst(regex, newString); 当我想替换像{*}这样的字符串的第一次出现时,正则表达式是什么样子的 我试过这个 url = url.replaceFirst(Pattern.quote("{") + "*" + Pattern.quote("}"), p
String s = "This is a test {replace_me}. And this is another {replace_me_too}."
s.replaceFirst(regex, newString);
当我想替换像{*}这样的字符串的第一次出现时,正则表达式是什么样子的
我试过这个
url = url.replaceFirst(Pattern.quote("{") + "*" + Pattern.quote("}"), param);
如果需要,可以使用replaceAll函数替换所有发生的事件
Java代码
url=url.replaceFirstPattern.quote{+*+Pattern.quote},参数;但它不会替换整个搜索字符串。请将其添加到您的问题中,然后您对此有答案吗?您正在使用的语言?检查此项:-更新了链接
String REGEX = "\\{[^}]*\\}";
String INPUT = "This is a test {replace_me}. And this is another {replace_me_too}.";
String REPLACE = "xxx";
Pattern p = Pattern.compile(REGEX);
Matcher m = p.matcher(INPUT);
INPUT = m.replaceFirst(REPLACE);
System.out.println(INPUT);