Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/381.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.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_Replace_Inverse - Fatal编程技术网

Java 如何对正则表达式求反

Java 如何对正则表达式求反,java,regex,replace,inverse,Java,Regex,Replace,Inverse,我正在使用Java正则表达式。 我有一个字符串如下 String s = "the location is at {emp.address.street} with the name {emp.name},{emp.surname}"; 对于上述字符串,s.replaceAll(“\\{(.*?\\},”)返回以下字符串: 位置位于,名称为, 现在我想将其反转,得到以下结果: {emp.address.street}{emp.name}{emp.surname}您可以创建一个模式并使用Matc

我正在使用Java正则表达式。 我有一个字符串如下

String s = "the location is at {emp.address.street} with the name {emp.name},{emp.surname}";
对于上述字符串,
s.replaceAll(“\\{(.*?\\},”)
返回以下字符串:

位置位于,名称为,

现在我想将其反转,得到以下结果:


{emp.address.street}{emp.name}{emp.surname}
您可以创建一个
模式
并使用
Matcher.find()
Matcher.group()
获取该模式的部分。
下面是类的Javadocs:

这个经过测试的脚本适合我:

公共类测试
{
公共静态void main(字符串[]args)
{
String s=“该位置位于{emp.address.street},名称为{emp.name},{emp.lasname}”;
字符串结果=s.replaceAll(“[^{}]+|(\\{(.*?\})”,“$1”);
系统输出打印项次(结果);
}
}

太好了……您能解释一下它是如何工作的吗?1美元的作用是什么?