如题,需要把以下字符串替换成"\r\n]",即一个换行加中括号"]",请问该怎么写?最好能够讲解一下,鄙人对正则表达式不太精通,不尽感谢。,
{
    xtype:'tbseparator',
    width:10,
    height:17
},
]

解决方案 »

  1.   

    replace(",\\r\\n{\\r\\n\\s*xtype:'tbseparator',\\r\\n\\s*width:10,\\r\\n\\s*height:17
    },","")
      

  2.   

        xtype:'tbseparator',
        width:10,
        height:17
    这一段是可以变化的吧,,只是具有xxxx:'xxxx'这样的格式对吗?
      

  3.   

    这段字符串里面有很多个形如
    {
        xtype:'tbseparator',
        width:10,
        height:17
    }的子字符串,我只需要把不用的替换掉,所以不能去掉空格
      

  4.   

    你这需求最好用javascript 处理,"\r\n"变"\r\n]" 只一 replace 就可了:
    // import java.util.*;public class Test1{
    public static void main(String args[]){
    String str=",\r\n{\r\n    xtype:'tbseparator',\r\n    width:10,";    // height:17
    // },
    // ]
      str=str.replaceAll("\r\n", "\r\n]");         
      System.out.println(str);       
        
    }
    }