Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 非常简单的专家正则表达式_Java_Regex - Fatal编程技术网

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);