我正在使用 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}
最佳答案
这个经过测试的脚本对我有用:
public class TEST
{
public static void main( String[] args )
{
String s = "the location is at {emp.address.street} with the name {emp.name},{emp.surname}";
String result = s.replaceAll( "[^{}]+|(\\{(.*?)\\})", "$1" );
System.out.println(result);
}
}
关于java - 如何对正则表达式取反,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7721063/